| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include <rtthread.h>
- #define TEST_NAME "shorthash"
- #include <assert.h>
- #include <errno.h>
- #include <limits.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <string.h>
- #include "sodium.h"
- #define MAXLEN 64
- static char results[] = "\
- 310e0edd47db6f72\n\
- fd67dc93c539f874\n\
- 5a4fa9d909806c0d\n\
- 2d7efbd796666785\n\
- b7877127e09427cf\n\
- 8da699cd64557618\n\
- cee3fe586e46c9cb\n\
- 37d1018bf50002ab\n\
- 6224939a79f5f593\n\
- b0e4a90bdf82009e\n\
- f3b9dd94c5bb5d7a\n\
- a7ad6b22462fb3f4\n\
- fbe50e86bc8f1e75\n\
- 903d84c02756ea14\n\
- eef27a8e90ca23f7\n\
- e545be4961ca29a1\n\
- db9bc2577fcc2a3f\n\
- 9447be2cf5e99a69\n\
- 9cd38d96f0b3c14b\n\
- bd6179a71dc96dbb\n\
- 98eea21af25cd6be\n\
- c7673b2eb0cbf2d0\n\
- 883ea3e395675393\n\
- c8ce5ccd8c030ca8\n\
- 94af49f6c650adb8\n\
- eab8858ade92e1bc\n\
- f315bb5bb835d817\n\
- adcf6b0763612e2f\n\
- a5c91da7acaa4dde\n\
- 716595876650a2a6\n\
- 28ef495c53a387ad\n\
- 42c341d8fa92d832\n\
- ce7cf2722f512771\n\
- e37859f94623f3a7\n\
- 381205bb1ab0e012\n\
- ae97a10fd434e015\n\
- b4a31508beff4d31\n\
- 81396229f0907902\n\
- 4d0cf49ee5d4dcca\n\
- 5c73336a76d8bf9a\n\
- d0a704536ba93e0e\n\
- 925958fcd6420cad\n\
- a915c29bc8067318\n\
- 952b79f3bc0aa6d4\n\
- f21df2e41d4535f9\n\
- 87577519048f53a9\n\
- 10a56cf5dfcd9adb\n\
- eb75095ccd986cd0\n\
- 51a9cb9ecba312e6\n\
- 96afadfc2ce666c7\n\
- 72fe52975a4364ee\n\
- 5a1645b276d592a1\n\
- b274cb8ebf87870a\n\
- 6f9bb4203de7b381\n\
- eaecb2a30b22a87f\n\
- 9924a43cc1315724\n\
- bd838d3aafbf8db7\n\
- 0b1a2a3265d51aea\n\
- 135079a3231ce660\n\
- 932b2846e4d70666\n\
- e1915f5cb1eca46c\n\
- f325965ca16d629f\n\
- 575ff28e60381be5\n\
- 724506eb4c328a95\n\
- ";
- int
- libsodium_short_hash_test(void)
- {
- char* output = (char*) malloc(sizeof(char) * 1089);
- if(output == NULL)
- {
- printf("Failed to malloc memory\n");
- return -1;
- }
- unsigned char in[MAXLEN];
- unsigned char out[crypto_shorthash_BYTES];
- unsigned char k[crypto_shorthash_KEYBYTES];
- size_t i;
- size_t j;
- for (i = 0; i < crypto_shorthash_KEYBYTES; ++i) {
- k[i] = (unsigned char) i;
- }
- for (i = 0; i < MAXLEN; ++i) {
- in[i] = (unsigned char) i;
- crypto_shorthash(out, in, (unsigned long long) i, k);
- for (j = 0; j < crypto_shorthash_BYTES; ++j) {
- sprintf(output + strlen(output), "%02x", (unsigned int) out[j]);
- }
- sprintf(output + strlen(output), "\n");
- }
- printf("%s", output);
- assert(strcmp(output, results) == 0);
- assert(crypto_shorthash_bytes() > 0);
- assert(crypto_shorthash_keybytes() > 0);
- assert(strcmp(crypto_shorthash_primitive(), "siphash24") == 0);
- assert(crypto_shorthash_bytes() == crypto_shorthash_siphash24_bytes());
- assert(crypto_shorthash_keybytes() ==
- crypto_shorthash_siphash24_keybytes());
- printf("\n====== SHORT HASH TEST PASS ======\n");
- return 0;
- }
- MSH_CMD_EXPORT(libsodium_short_hash_test, libsodium short hash test)
|