2013-04-21 08:26:34 -04:00
|
|
|
|
|
|
|
#define TEST_NAME "generichash2"
|
|
|
|
#include "cmptest.h"
|
|
|
|
|
2015-10-17 18:55:10 -04:00
|
|
|
int
|
|
|
|
main(void)
|
2013-04-21 08:26:34 -04:00
|
|
|
{
|
|
|
|
#define MAXLEN 64
|
|
|
|
crypto_generichash_state st;
|
2014-09-14 14:32:55 -04:00
|
|
|
unsigned char in[MAXLEN], out[crypto_generichash_BYTES_MAX],
|
|
|
|
k[crypto_generichash_KEYBYTES_MAX];
|
2014-11-20 15:00:37 -05:00
|
|
|
size_t h, i, j;
|
2013-04-21 08:26:34 -04:00
|
|
|
|
2015-10-17 18:16:05 -04:00
|
|
|
assert(crypto_generichash_statebytes() >= sizeof st);
|
2014-09-14 14:32:55 -04:00
|
|
|
for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h)
|
2016-03-07 09:45:59 -05:00
|
|
|
k[h] = (unsigned char) h;
|
2013-04-21 08:26:34 -04:00
|
|
|
|
2014-09-14 14:32:55 -04:00
|
|
|
for (i = 0; i < MAXLEN; ++i) {
|
2016-03-07 09:45:59 -05:00
|
|
|
in[i] = (unsigned char) i;
|
2014-09-17 00:41:33 -04:00
|
|
|
if (crypto_generichash_init(&st, k,
|
|
|
|
1 + i % crypto_generichash_KEYBYTES_MAX,
|
|
|
|
1 + i % crypto_generichash_BYTES_MAX) != 0) {
|
|
|
|
printf("crypto_generichash_init()\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-04-21 08:26:34 -04:00
|
|
|
crypto_generichash_update(&st, in, i);
|
|
|
|
crypto_generichash_update(&st, in, i);
|
|
|
|
crypto_generichash_update(&st, in, i);
|
2014-09-14 14:32:55 -04:00
|
|
|
crypto_generichash_final(&st, out,
|
|
|
|
1 + i % crypto_generichash_BYTES_MAX);
|
|
|
|
for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
|
|
|
|
printf("%02x", (unsigned int)out[j]);
|
2013-04-21 08:26:34 -04:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2014-09-14 15:56:32 -04:00
|
|
|
|
|
|
|
assert(crypto_generichash_init(&st, k, sizeof k, 0U) == -1);
|
|
|
|
assert(crypto_generichash_init(&st, k, sizeof k,
|
|
|
|
crypto_generichash_BYTES_MAX + 1U) == -1);
|
|
|
|
assert(crypto_generichash_init(&st, k, crypto_generichash_KEYBYTES_MAX + 1U,
|
|
|
|
sizeof out) == -1);
|
2014-09-16 17:44:38 -04:00
|
|
|
assert(crypto_generichash_init(&st, k, 0U, sizeof out) == 0);
|
|
|
|
assert(crypto_generichash_init(&st, k, 1U, sizeof out) == 0);
|
|
|
|
assert(crypto_generichash_init(&st, NULL, 1U, 0U) == -1);
|
|
|
|
assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
|
|
|
|
1U) == 0);
|
|
|
|
assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
|
|
|
|
0U) == -1);
|
2013-04-21 08:26:34 -04:00
|
|
|
return 0;
|
|
|
|
}
|