You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

  1. #define TEST_NAME "hash"
  2. #include "cmptest.h"
  3. unsigned char x[] = "testing\n";
  4. unsigned char x2[] = "The Conscience of a Hacker is a small essay written January 8, 1986 by a computer security hacker who went by the handle of The Mentor, who belonged to the 2nd generation of Legion of Doom.";
  5. unsigned char h[crypto_hash_BYTES];
  6. int main(void)
  7. {
  8. size_t i;
  9. crypto_hash(h, x, sizeof x - 1U);
  10. for (i = 0; i < crypto_hash_BYTES; ++i) {
  11. printf("%02x", (unsigned int)h[i]);
  12. }
  13. printf("\n");
  14. crypto_hash(h, x2, sizeof x2 - 1U);
  15. for (i = 0; i < crypto_hash_BYTES; ++i) {
  16. printf("%02x", (unsigned int)h[i]);
  17. }
  18. printf("\n");
  19. crypto_hash_sha256(h, x, sizeof x - 1U);
  20. for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
  21. printf("%02x", (unsigned int)h[i]);
  22. }
  23. printf("\n");
  24. crypto_hash_sha256(h, x2, sizeof x2 - 1U);
  25. for (i = 0; i < crypto_hash_sha256_BYTES; ++i) {
  26. printf("%02x", (unsigned int)h[i]);
  27. }
  28. printf("\n");
  29. assert(crypto_hash_bytes() > 0U);
  30. assert(strcmp(crypto_hash_primitive(), "sha512") == 0);
  31. assert(crypto_hash_sha256_bytes() > 0U);
  32. assert(crypto_hash_sha512_bytes() >= crypto_hash_sha256_bytes());
  33. assert(crypto_hash_sha512_bytes() == crypto_hash_bytes());
  34. return 0;
  35. }