Home | History | Annotate | Line # | Download | only in default
      1  1.1  riastrad 
      2  1.1  riastrad #define TEST_NAME "generichash2"
      3  1.1  riastrad #include "cmptest.h"
      4  1.1  riastrad 
      5  1.1  riastrad int
      6  1.1  riastrad main(void)
      7  1.1  riastrad {
      8  1.1  riastrad #define MAXLEN 64
      9  1.1  riastrad     crypto_generichash_state st;
     10  1.1  riastrad     unsigned char in[MAXLEN], out[crypto_generichash_BYTES_MAX],
     11  1.1  riastrad         k[crypto_generichash_KEYBYTES_MAX];
     12  1.1  riastrad     size_t h, i, j;
     13  1.1  riastrad 
     14  1.1  riastrad     assert(crypto_generichash_statebytes() >= sizeof st);
     15  1.1  riastrad     for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h)
     16  1.1  riastrad         k[h] = (unsigned char) h;
     17  1.1  riastrad 
     18  1.1  riastrad     for (i = 0; i < MAXLEN; ++i) {
     19  1.1  riastrad         in[i] = (unsigned char) i;
     20  1.1  riastrad         if (crypto_generichash_init(&st, k,
     21  1.1  riastrad                                     1 + i % crypto_generichash_KEYBYTES_MAX,
     22  1.1  riastrad                                     1 + i % crypto_generichash_BYTES_MAX) != 0) {
     23  1.1  riastrad             printf("crypto_generichash_init()\n");
     24  1.1  riastrad             return 1;
     25  1.1  riastrad         }
     26  1.1  riastrad         crypto_generichash_update(&st, in, i);
     27  1.1  riastrad         crypto_generichash_update(&st, in, i);
     28  1.1  riastrad         crypto_generichash_update(&st, in, i);
     29  1.1  riastrad         if (crypto_generichash_final(&st, out,
     30  1.1  riastrad                                      1 + i % crypto_generichash_BYTES_MAX) != 0) {
     31  1.1  riastrad             printf("crypto_generichash_final() should have returned 0\n");
     32  1.1  riastrad         }
     33  1.1  riastrad         for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
     34  1.1  riastrad             printf("%02x", (unsigned int)out[j]);
     35  1.1  riastrad         }
     36  1.1  riastrad         printf("\n");
     37  1.1  riastrad         if (crypto_generichash_final(&st, out,
     38  1.1  riastrad                                      1 + i % crypto_generichash_BYTES_MAX) != -1) {
     39  1.1  riastrad             printf("crypto_generichash_final() should have returned -1\n");
     40  1.1  riastrad         }
     41  1.1  riastrad     }
     42  1.1  riastrad 
     43  1.1  riastrad     assert(crypto_generichash_init(&st, k, sizeof k, 0U) == -1);
     44  1.1  riastrad     assert(crypto_generichash_init(&st, k, sizeof k,
     45  1.1  riastrad                                    crypto_generichash_BYTES_MAX + 1U) == -1);
     46  1.1  riastrad     assert(crypto_generichash_init(&st, k, crypto_generichash_KEYBYTES_MAX + 1U,
     47  1.1  riastrad                                    sizeof out) == -1);
     48  1.1  riastrad     assert(crypto_generichash_init(&st, k, 0U, sizeof out) == 0);
     49  1.1  riastrad     assert(crypto_generichash_init(&st, k, 1U, sizeof out) == 0);
     50  1.1  riastrad     assert(crypto_generichash_init(&st, NULL, 1U, 0U) == -1);
     51  1.1  riastrad     assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
     52  1.1  riastrad                                    1U) == 0);
     53  1.1  riastrad     assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
     54  1.1  riastrad                                    0U) == -1);
     55  1.1  riastrad     return 0;
     56  1.1  riastrad }
     57