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.

174 lines
7.6 KiB

  1. #define TEST_NAME "generichash3"
  2. #include "cmptest.h"
  3. int main(void)
  4. {
  5. #define MAXLEN 64
  6. crypto_generichash_blake2b_state st;
  7. unsigned char salt[crypto_generichash_blake2b_SALTBYTES]
  8. = { '5', 'b', '6', 'b', '4', '1', 'e', 'd',
  9. '9', 'b', '3', '4', '3', 'f', 'e', '0' };
  10. unsigned char personal[crypto_generichash_blake2b_PERSONALBYTES]
  11. = { '5', '1', '2', '6', 'f', 'b', '2', 'a',
  12. '3', '7', '4', '0', '0', 'd', '2', 'a' };
  13. unsigned char in[MAXLEN];
  14. unsigned char out[crypto_generichash_blake2b_BYTES_MAX];
  15. unsigned char k[crypto_generichash_blake2b_KEYBYTES_MAX];
  16. size_t h;
  17. size_t i;
  18. size_t j;
  19. for (h = 0; h < crypto_generichash_blake2b_KEYBYTES_MAX; ++h) {
  20. k[h] = (unsigned char) h;
  21. }
  22. for (i = 0; i < MAXLEN; ++i) {
  23. in[i] = (unsigned char) i;
  24. crypto_generichash_blake2b_init_salt_personal(
  25. &st, k, 1 + i % crypto_generichash_blake2b_KEYBYTES_MAX,
  26. 1 + i % crypto_generichash_blake2b_BYTES_MAX, salt, personal);
  27. crypto_generichash_blake2b_update(&st, in, (unsigned long long) i);
  28. crypto_generichash_blake2b_final(
  29. &st, out, 1 + i % crypto_generichash_blake2b_BYTES_MAX);
  30. for (j = 0; j < 1 + i % crypto_generichash_blake2b_BYTES_MAX; ++j) {
  31. printf("%02x", (unsigned int) out[j]);
  32. }
  33. printf("\n");
  34. }
  35. memset(out, 0, sizeof out);
  36. crypto_generichash_blake2b_init_salt_personal(
  37. &st, k, 0U, crypto_generichash_blake2b_BYTES_MAX, salt, personal);
  38. crypto_generichash_blake2b_update(&st, in, MAXLEN);
  39. crypto_generichash_blake2b_final(&st, out,
  40. crypto_generichash_blake2b_BYTES_MAX);
  41. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  42. printf("%02x", (unsigned int) out[j]);
  43. }
  44. printf("\n");
  45. memset(out, 0, sizeof out);
  46. crypto_generichash_blake2b_init_salt_personal(
  47. &st, NULL, 1U, crypto_generichash_blake2b_BYTES_MAX, salt, personal);
  48. crypto_generichash_blake2b_update(&st, in, MAXLEN);
  49. crypto_generichash_blake2b_final(&st, out,
  50. crypto_generichash_blake2b_BYTES_MAX);
  51. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  52. printf("%02x", (unsigned int) out[j]);
  53. }
  54. printf("\n");
  55. memset(out, 0, sizeof out);
  56. crypto_generichash_blake2b_init_salt_personal(
  57. &st, k, crypto_generichash_blake2b_KEYBYTES_MAX,
  58. crypto_generichash_blake2b_BYTES_MAX, NULL, personal);
  59. crypto_generichash_blake2b_update(&st, in, MAXLEN);
  60. crypto_generichash_blake2b_final(&st, out,
  61. crypto_generichash_blake2b_BYTES_MAX);
  62. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  63. printf("%02x", (unsigned int) out[j]);
  64. }
  65. printf("\n");
  66. memset(out, 0, sizeof out);
  67. crypto_generichash_blake2b_init_salt_personal(
  68. &st, k, crypto_generichash_blake2b_KEYBYTES_MAX,
  69. crypto_generichash_blake2b_BYTES_MAX, salt, NULL);
  70. crypto_generichash_blake2b_update(&st, in, MAXLEN);
  71. assert(crypto_generichash_blake2b_final(
  72. &st, out, crypto_generichash_blake2b_BYTES_MAX + 1U) == -1);
  73. crypto_generichash_blake2b_final(
  74. &st, out, crypto_generichash_blake2b_BYTES_MAX);
  75. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  76. printf("%02x", (unsigned int) out[j]);
  77. }
  78. printf("\n");
  79. memset(out, 0, sizeof out);
  80. crypto_generichash_blake2b_salt_personal(
  81. out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
  82. k, 0U, salt, personal);
  83. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  84. printf("%02x", (unsigned int) out[j]);
  85. }
  86. printf("\n");
  87. memset(out, 0, sizeof out);
  88. crypto_generichash_blake2b_salt_personal(
  89. out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
  90. NULL, crypto_generichash_blake2b_KEYBYTES_MAX, salt, personal);
  91. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  92. printf("%02x", (unsigned int) out[j]);
  93. }
  94. printf("\n");
  95. memset(out, 0, sizeof out);
  96. crypto_generichash_blake2b_salt_personal(
  97. out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
  98. k, crypto_generichash_blake2b_KEYBYTES_MAX, salt, personal);
  99. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  100. printf("%02x", (unsigned int) out[j]);
  101. }
  102. printf("\n");
  103. memset(out, 0, sizeof out);
  104. crypto_generichash_blake2b_salt_personal(
  105. out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
  106. k, crypto_generichash_blake2b_KEYBYTES_MAX, NULL, personal);
  107. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  108. printf("%02x", (unsigned int) out[j]);
  109. }
  110. printf("\n");
  111. memset(out, 0, sizeof out);
  112. crypto_generichash_blake2b_salt_personal(
  113. out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN,
  114. k, crypto_generichash_blake2b_KEYBYTES_MAX, salt, NULL);
  115. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  116. printf("%02x", (unsigned int) out[j]);
  117. }
  118. printf("\n");
  119. crypto_generichash_blake2b_init_salt_personal(&st, NULL, 0U, crypto_generichash_BYTES,
  120. NULL, personal);
  121. crypto_generichash_blake2b_update(&st, in, MAXLEN);
  122. crypto_generichash_blake2b_final(&st, out, crypto_generichash_blake2b_BYTES_MAX);
  123. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  124. printf("%02x", (unsigned int) out[j]);
  125. }
  126. printf("\n");
  127. crypto_generichash_blake2b_init_salt_personal(&st, NULL, 0U, crypto_generichash_BYTES,
  128. salt, NULL);
  129. crypto_generichash_blake2b_update(&st, in, MAXLEN);
  130. crypto_generichash_blake2b_final(&st, out, crypto_generichash_blake2b_BYTES_MAX);
  131. for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) {
  132. printf("%02x", (unsigned int) out[j]);
  133. }
  134. printf("\n");
  135. assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, 0U,
  136. salt, personal) == -1);
  137. assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k,
  138. crypto_generichash_BYTES_MAX + 1U,
  139. salt, personal) == -1);
  140. assert(crypto_generichash_blake2b_init_salt_personal(&st, k,
  141. crypto_generichash_KEYBYTES_MAX + 1U,
  142. sizeof out, salt, personal) == -1);
  143. assert(crypto_generichash_blake2b_salt_personal(out, 0U, in, MAXLEN,
  144. k, sizeof k,
  145. salt, personal) == -1);
  146. assert(crypto_generichash_blake2b_salt_personal(out, crypto_generichash_BYTES_MAX + 1U,
  147. in, MAXLEN, k, sizeof k,
  148. salt, personal) == -1);
  149. assert(crypto_generichash_blake2b_salt_personal(out, sizeof out, in, MAXLEN,
  150. k, crypto_generichash_KEYBYTES_MAX + 1U,
  151. salt, personal) == -1);
  152. assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, crypto_generichash_BYTES,
  153. NULL, personal) == 0);
  154. assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, crypto_generichash_BYTES,
  155. salt, NULL) == 0);
  156. return 0;
  157. }