Scrypt.c 799 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // Scrypt.c
  3. // Threema
  4. //
  5. // Copyright © 2018 Threema GmbH. All rights reserved.
  6. //
  7. #include "Scrypt.h"
  8. #include "include/scrypt.h"
  9. #include "string.h"
  10. #include "limits.h"
  11. // see on https://github.com/derivepass/scrypt
  12. int getDerivedKey(char password[], char salt[], uint8_t out[64]) {
  13. int err;
  14. scrypt_state_t state;
  15. if(!password || !salt || !out) {
  16. return 1;
  17. }
  18. state.n = 65536;
  19. state.r = 8;
  20. state.p = 1;
  21. err = scrypt_state_init(&state);
  22. //assert(err == 0);
  23. if(err != 0) {
  24. return err;
  25. }
  26. scrypt(&state,
  27. (const uint8_t*) password,
  28. strlen(password),
  29. (const uint8_t*) salt,
  30. strlen(salt),
  31. out,
  32. 64);
  33. scrypt_state_destroy(&state);
  34. return 0;
  35. }