scrypt-jane-hash.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #if defined(SCRYPT_BLAKE512)
  2. #include "scrypt-jane-hash_blake512.h"
  3. #elif defined(SCRYPT_BLAKE256)
  4. #include "scrypt-jane-hash_blake256.h"
  5. #elif defined(SCRYPT_SHA512)
  6. #include "scrypt-jane-hash_sha512.h"
  7. #elif defined(SCRYPT_SHA256)
  8. #include "scrypt-jane-hash_sha256.h"
  9. #elif defined(SCRYPT_SKEIN512)
  10. #include "scrypt-jane-hash_skein512.h"
  11. #elif defined(SCRYPT_KECCAK512) || defined(SCRYPT_KECCAK256)
  12. #include "scrypt-jane-hash_keccak.h"
  13. #else
  14. #define SCRYPT_HASH "ERROR"
  15. #define SCRYPT_HASH_BLOCK_SIZE 64
  16. #define SCRYPT_HASH_DIGEST_SIZE 64
  17. typedef struct scrypt_hash_state_t { size_t dummy; } scrypt_hash_state;
  18. typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE];
  19. static void scrypt_hash_init(scrypt_hash_state *S) {}
  20. static void scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) {}
  21. static void scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) {}
  22. static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = {0};
  23. #error must define a hash function!
  24. #endif
  25. #include "scrypt-jane-pbkdf2.h"
  26. #define SCRYPT_TEST_HASH_LEN 257 /* (2 * largest block size) + 1 */
  27. static int
  28. scrypt_test_hash() {
  29. scrypt_hash_state st;
  30. scrypt_hash_digest hash, final;
  31. uint8_t msg[SCRYPT_TEST_HASH_LEN];
  32. size_t i;
  33. for (i = 0; i < SCRYPT_TEST_HASH_LEN; i++)
  34. msg[i] = (uint8_t)i;
  35. scrypt_hash_init(&st);
  36. for (i = 0; i < SCRYPT_TEST_HASH_LEN + 1; i++) {
  37. scrypt_hash(hash, msg, i);
  38. scrypt_hash_update(&st, hash, sizeof(hash));
  39. }
  40. scrypt_hash_finish(&st, final);
  41. return scrypt_verify(final, scrypt_test_hash_expected, SCRYPT_HASH_DIGEST_SIZE);
  42. }