xref: /freebsd/sys/contrib/libsodium/test/default/shorthash.c (revision 3611ec604864a7d4dcc9a3ea898c80eb35eef8a0)
1*0ac341f1SConrad Meyer 
2*0ac341f1SConrad Meyer #define TEST_NAME "shorthash"
3*0ac341f1SConrad Meyer #include "cmptest.h"
4*0ac341f1SConrad Meyer 
5*0ac341f1SConrad Meyer #define MAXLEN 64
6*0ac341f1SConrad Meyer 
7*0ac341f1SConrad Meyer int
main(void)8*0ac341f1SConrad Meyer main(void)
9*0ac341f1SConrad Meyer {
10*0ac341f1SConrad Meyer     unsigned char in[MAXLEN];
11*0ac341f1SConrad Meyer     unsigned char out[crypto_shorthash_BYTES];
12*0ac341f1SConrad Meyer     unsigned char k[crypto_shorthash_KEYBYTES];
13*0ac341f1SConrad Meyer     size_t        i;
14*0ac341f1SConrad Meyer     size_t        j;
15*0ac341f1SConrad Meyer 
16*0ac341f1SConrad Meyer     for (i = 0; i < crypto_shorthash_KEYBYTES; ++i) {
17*0ac341f1SConrad Meyer         k[i] = (unsigned char) i;
18*0ac341f1SConrad Meyer     }
19*0ac341f1SConrad Meyer     for (i = 0; i < MAXLEN; ++i) {
20*0ac341f1SConrad Meyer         in[i] = (unsigned char) i;
21*0ac341f1SConrad Meyer         crypto_shorthash(out, in, (unsigned long long) i, k);
22*0ac341f1SConrad Meyer         for (j = 0; j < crypto_shorthash_BYTES; ++j) {
23*0ac341f1SConrad Meyer             printf("%02x", (unsigned int) out[j]);
24*0ac341f1SConrad Meyer         }
25*0ac341f1SConrad Meyer         printf("\n");
26*0ac341f1SConrad Meyer     }
27*0ac341f1SConrad Meyer     assert(crypto_shorthash_bytes() > 0);
28*0ac341f1SConrad Meyer     assert(crypto_shorthash_keybytes() > 0);
29*0ac341f1SConrad Meyer     assert(strcmp(crypto_shorthash_primitive(), "siphash24") == 0);
30*0ac341f1SConrad Meyer     assert(crypto_shorthash_bytes() == crypto_shorthash_siphash24_bytes());
31*0ac341f1SConrad Meyer     assert(crypto_shorthash_keybytes() ==
32*0ac341f1SConrad Meyer            crypto_shorthash_siphash24_keybytes());
33*0ac341f1SConrad Meyer 
34*0ac341f1SConrad Meyer     return 0;
35*0ac341f1SConrad Meyer }
36