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.

48 lines
1.8 KiB

  1. #define TEST_NAME "generichash2"
  2. #include "cmptest.h"
  3. int main(void)
  4. {
  5. #define MAXLEN 64
  6. crypto_generichash_state st;
  7. unsigned char in[MAXLEN], out[crypto_generichash_BYTES_MAX],
  8. k[crypto_generichash_KEYBYTES_MAX];
  9. size_t h, i, j;
  10. for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h)
  11. k[h] = h;
  12. for (i = 0; i < MAXLEN; ++i) {
  13. in[i] = i;
  14. if (crypto_generichash_init(&st, k,
  15. 1 + i % crypto_generichash_KEYBYTES_MAX,
  16. 1 + i % crypto_generichash_BYTES_MAX) != 0) {
  17. printf("crypto_generichash_init()\n");
  18. return 1;
  19. }
  20. crypto_generichash_update(&st, in, i);
  21. crypto_generichash_update(&st, in, i);
  22. crypto_generichash_update(&st, in, i);
  23. crypto_generichash_final(&st, out,
  24. 1 + i % crypto_generichash_BYTES_MAX);
  25. for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
  26. printf("%02x", (unsigned int)out[j]);
  27. }
  28. printf("\n");
  29. }
  30. assert(crypto_generichash_init(&st, k, sizeof k, 0U) == -1);
  31. assert(crypto_generichash_init(&st, k, sizeof k,
  32. crypto_generichash_BYTES_MAX + 1U) == -1);
  33. assert(crypto_generichash_init(&st, k, crypto_generichash_KEYBYTES_MAX + 1U,
  34. sizeof out) == -1);
  35. assert(crypto_generichash_init(&st, k, 0U, sizeof out) == 0);
  36. assert(crypto_generichash_init(&st, k, 1U, sizeof out) == 0);
  37. assert(crypto_generichash_init(&st, NULL, 1U, 0U) == -1);
  38. assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
  39. 1U) == 0);
  40. assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
  41. 0U) == -1);
  42. return 0;
  43. }