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.

79 lines
3.0 KiB

  1. #define TEST_NAME "generichash"
  2. #include "cmptest.h"
  3. #define MAXLEN 64
  4. int main(void)
  5. {
  6. unsigned char in[MAXLEN];
  7. unsigned char out[crypto_generichash_BYTES_MAX];
  8. unsigned char k[crypto_generichash_KEYBYTES_MAX];
  9. size_t h;
  10. size_t i;
  11. size_t j;
  12. for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h) {
  13. k[h] = (unsigned char) h;
  14. }
  15. for (i = 0; i < MAXLEN; ++i) {
  16. in[i] = (unsigned char) i;
  17. crypto_generichash(out, 1 + i % crypto_generichash_BYTES_MAX, in,
  18. (unsigned long long) i, k,
  19. 1 + i % crypto_generichash_KEYBYTES_MAX);
  20. for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
  21. printf("%02x", (unsigned int) out[j]);
  22. }
  23. printf("\n");
  24. }
  25. memset(out, 0, sizeof out);
  26. crypto_generichash(out, crypto_generichash_BYTES_MAX, in,
  27. (unsigned long long) i, k, 0U);
  28. for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) {
  29. printf("%02x", (unsigned int) out[j]);
  30. }
  31. printf("\n");
  32. memset(out, 0, sizeof out);
  33. crypto_generichash(out, crypto_generichash_BYTES_MAX, in,
  34. (unsigned long long) i, NULL, 1U);
  35. for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) {
  36. printf("%02x", (unsigned int) out[j]);
  37. }
  38. printf("\n");
  39. assert(crypto_generichash(out, 0U, in, sizeof in, k, sizeof k) == -1);
  40. assert(crypto_generichash(out, crypto_generichash_BYTES_MAX + 1U,
  41. in, sizeof in, k, sizeof k) == -1);
  42. assert(crypto_generichash(out, sizeof out, in, sizeof in,
  43. k, crypto_generichash_KEYBYTES_MAX + 1U) == -1);
  44. assert(crypto_generichash_bytes_min() > 0U);
  45. assert(crypto_generichash_bytes_max() > 0U);
  46. assert(crypto_generichash_bytes() > 0U);
  47. assert(crypto_generichash_bytes() >= crypto_generichash_bytes_min());
  48. assert(crypto_generichash_bytes() <= crypto_generichash_bytes_max());
  49. assert(crypto_generichash_keybytes_min() > 0U);
  50. assert(crypto_generichash_keybytes_max() > 0U);
  51. assert(crypto_generichash_keybytes() > 0U);
  52. assert(crypto_generichash_keybytes() >= crypto_generichash_keybytes_min());
  53. assert(crypto_generichash_keybytes() <= crypto_generichash_keybytes_max());
  54. assert(strcmp(crypto_generichash_primitive(), "blake2b") == 0);
  55. assert(crypto_generichash_bytes_min()
  56. == crypto_generichash_blake2b_bytes_min());
  57. assert(crypto_generichash_bytes_max()
  58. == crypto_generichash_blake2b_bytes_max());
  59. assert(crypto_generichash_bytes() == crypto_generichash_blake2b_bytes());
  60. assert(crypto_generichash_keybytes_min()
  61. == crypto_generichash_blake2b_keybytes_min());
  62. assert(crypto_generichash_keybytes_max()
  63. == crypto_generichash_blake2b_keybytes_max());
  64. assert(crypto_generichash_keybytes()
  65. == crypto_generichash_blake2b_keybytes());
  66. assert(crypto_generichash_blake2b_saltbytes() > 0U);
  67. assert(crypto_generichash_blake2b_personalbytes() > 0U);
  68. return 0;
  69. }