[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stand-alone code for scrypt



Here are steps to get the function crypto_scrypt() into a single .h file
and a
single .c file, i.e., a single .h/.c pair. This is similar to SQLite,
which is
also provided in a single .h/.c pair. Unfortunately, unlike with SQLite, you
may have to repeat these steps for each platform.

I performed these steps on OS X Yosemite 10.10.1 with Xcode 6.1 and
associated command line tools installed. Some of these steps may be
different on your platform, so adjust them accordingly.

1. Download a fresh copy of scrypt-1.1.6.tgz from
https://www.tarsnap.com/scrypt.html

2. Make sure it has the right SHA-256 hash:
dfd0d1a544439265bbb9b58043ad3c8ce50a3987b44a61b1d39fd7a3ed5b7fb8
On OS X, this is done with "shasum -a 256 scrypt-1.1.6.tgz"

3. Extract the archive.

4. Run "./configure && make" to make your config.h file ready for your
platform.

5. Delete all the files except for config.h, crypto_scrypt.h,
crypto_scrypt-sse.c, sha256.h, sha256.c, and sysendian.h. Put these files
together into the same folder (getting rid of any subfolder hierarchies).

6. Import these files into a throwaway C project that you can compile. We
will
now embark upon the task of combining these files into a single .h/.c pair.

7. Compile the project.

8. You will get errors on
#include "scrypt_platform.h"
because you deleted this file. Replace each occurrence of this line with
#include "config.h"

9. Now your project should compile without errors.

10. Remove the line
#include "sha256.h"
from crypto_scrypt-sse.c.

11. Copy the contents of sha256.h to the top of crypto_scrypt-sse.c.

12. Delete sha256.h.

13. Remove the line
#include "sha256.h"
from the sha256.c file.

14. Copy the contents of sha256.c to the bottom of crypto_scrypt-sse.c.

15. Delete sha256.c.

16. Now your project should compile without errors.

17. Copy the contents of sysendian.h to the top of crypto_scrypt-sse.c.

18. Delete sysendian.h.

19. Remove all occurrences of
#include "sysendian.h"
from crypto_scrypt-sse.c.

20. Now your project should compile without errors.

21. Copy the contents of config.h to the top of crypto_scrypt-sse.c.

22. Delete config.h.

23. Remove all occurrences of
#include "config.h"
from crypto_scrypt-sse.c.

24. Now your project should compile without errors.

25. You may get warnings about the unused functions be64dec(), be64enc(),
le64dec(), le64enc(). Delete these functions.

26. Rename crypto_scrypt-sse.c to crypto_scrypt.c.

27. You are now left with only two files: crypto_scrypt.h and
crypto_scrypt.c.

28. Put these two files on your desktop, and delete your throwaway C project.

29. You now have a single .h/.c pair that you can use in any C project to use
the crypto_scrypt() function. Enjoy!