diff options
Diffstat (limited to 'misc-tests.c')
-rw-r--r-- | misc-tests.c | 115 |
1 files changed, 114 insertions, 1 deletions
diff --git a/misc-tests.c b/misc-tests.c index 4eca0a6..7a5c546 100644 --- a/misc-tests.c +++ b/misc-tests.c @@ -53,6 +53,26 @@ eq(struct libhashsum_hasher *a, struct libhashsum_hasher *b) if (memcmp(&a->state, &b->state, sizeof(a->state))) return 0; break; + case LIBHASHSUM_BLAKE2S: +#ifdef LIBHASHSUM_INCLUDE_LIBBLAKE_STATE + if (memcmp(&a->state.blake2s.s, &b->state.blake2s.s, sizeof(a->state.blake2s.s))) + return 0; + if (a->state.blake2s.keybytes != b->state.blake2s.keybytes) + return 0; + if (a->state.blake2s.keybytes && memcmp(a->state.blake2s.buf, b->state.blake2s.buf, sizeof(a->state.blake2s.buf))) + return 0; +#endif + break; + case LIBHASHSUM_BLAKE2B: +#ifdef LIBHASHSUM_INCLUDE_LIBBLAKE_STATE + if (memcmp(&a->state.blake2b.s, &b->state.blake2b.s, sizeof(a->state.blake2b.s))) + return 0; + if (a->state.blake2b.keybytes != b->state.blake2b.keybytes) + return 0; + if (a->state.blake2b.keybytes && memcmp(a->state.blake2b.buf, b->state.blake2b.buf, sizeof(a->state.blake2b.buf))) + return 0; +#endif + break; case LIBHASHSUM_KECCAK: case LIBHASHSUM_KECCAK_224: case LIBHASHSUM_KECCAK_256: @@ -86,8 +106,8 @@ eq(struct libhashsum_hasher *a, struct libhashsum_hasher *b) if (r) return 0; } - break; #endif + break; default: abort(); } @@ -421,6 +441,10 @@ main(void) ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-256") == 0); ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-384") == 0); ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-512") == 0); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-2s") == 1 && algo == LIBHASHSUM_BLAKE2S); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE-2b") == 1 && algo == LIBHASHSUM_BLAKE2B); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-2s") == 0); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "B-2b") == 0); ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD128") == 1 && algo == LIBHASHSUM_RIPEMD_128); ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD160") == 1 && algo == LIBHASHSUM_RIPEMD_160); @@ -474,6 +498,10 @@ main(void) ASSERT(libhashsum_get_algorithm_from_string(&algo, "B256") == 1 && algo == LIBHASHSUM_BLAKE256); ASSERT(libhashsum_get_algorithm_from_string(&algo, "B384") == 1 && algo == LIBHASHSUM_BLAKE384); ASSERT(libhashsum_get_algorithm_from_string(&algo, "B512") == 1 && algo == LIBHASHSUM_BLAKE512); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2s") == 1 && algo == LIBHASHSUM_BLAKE2S); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2b") == 1 && algo == LIBHASHSUM_BLAKE2B); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2s") == 1 && algo == LIBHASHSUM_BLAKE2S); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2b") == 1 && algo == LIBHASHSUM_BLAKE2B); ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-128[]") == 0); ASSERT(libhashsum_get_algorithm_from_string(&algo, "RIPEMD-160[]") == 0); @@ -527,6 +555,10 @@ main(void) ASSERT(libhashsum_get_algorithm_from_string(&algo, "B256[]") == 1 && algo == LIBHASHSUM_BLAKE256); ASSERT(libhashsum_get_algorithm_from_string(&algo, "B384[]") == 1 && algo == LIBHASHSUM_BLAKE384); ASSERT(libhashsum_get_algorithm_from_string(&algo, "B512[]") == 1 && algo == LIBHASHSUM_BLAKE512); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2s[]") == 1 && algo == LIBHASHSUM_BLAKE2S); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "BLAKE2b[]") == 1 && algo == LIBHASHSUM_BLAKE2B); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2s[]") == 1 && algo == LIBHASHSUM_BLAKE2S); + ASSERT(libhashsum_get_algorithm_from_string(&algo, "B2b[]") == 1 && algo == LIBHASHSUM_BLAKE2B); #define CHECK(ALGO, CALL)\ do {\ @@ -634,6 +666,7 @@ main(void) CHECK("BLAKE512[SaLt=0X0123456789abcDef0123456789abcdef0123456789abcdef0123456789abcdef]", libhashsum_init_blake512_hasher(&hasher, SALT SALT)); CHECK("Keccak", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 0)); + CHECK("Keccak[]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 0)); CHECK("Keccak[r=256]", libhashsum_init_keccak_hasher(&hasher, 256, 0, 0, 0)); CHECK("Keccak[R=256]", libhashsum_init_keccak_hasher(&hasher, 256, 0, 0, 0)); CHECK("Keccak[c=256]", libhashsum_init_keccak_hasher(&hasher, 0, 256, 0, 0)); @@ -644,11 +677,50 @@ main(void) CHECK("Keccak[Z=256]", libhashsum_init_keccak_hasher(&hasher, 0, 0, 0, 256)); CHECK("Keccak[r=1200,c=400,n=100,z=60]", libhashsum_init_keccak_hasher(&hasher, 1200, 400, 100, 60)); CHECK("Keccak[z=60,r=1200,c=400,n=100]", libhashsum_init_keccak_hasher(&hasher, 1200, 400, 100, 60)); + CHECK("BLAKE2s", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2s[]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2s[n=128]", libhashsum_init_blake2s_hasher(&hasher, 128, NULL, NULL, NULL, 0)); + CHECK("BLAKE2s[Salt=0000000000000000]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2s[pePPer=0000000000000000]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2s[key=]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2s[salt=0123456789abcDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, SALT, NULL, NULL, 0)); + CHECK("BLAKE2s[pepper=0123456789abcDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, SALT, NULL, 0)); + CHECK("BLAKE2s[key=0123456789abcDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, SALT, 8)); + CHECK("BLAKE2s[KEY=0123456789abcdef0123456789ABCDEF]", libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, SALT, 16)); + CHECK("BLAKE2s[key=0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF]", + libhashsum_init_blake2s_hasher(&hasher, 0, NULL, NULL, SALT SALT, 32)); + CHECK("BLAKE2b", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[n=64]", libhashsum_init_blake2b_hasher(&hasher, 64, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[N=128]", libhashsum_init_blake2b_hasher(&hasher, 128, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[salt=0123456789abcDEF0123456789abcDEF]", + libhashsum_init_blake2b_hasher(&hasher, 0, SALT, NULL, NULL, 0)); + CHECK("BLAKE2b[pepper=0123456789abcDEF0123456789abcDEF]", + libhashsum_init_blake2b_hasher(&hasher, 0, NULL, SALT, NULL, 0)); + CHECK("BLAKE2b[key=0123456789abcDEF]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT, 8)); + CHECK("BLAKE2b[salt=00000000000000000000000000000000]", + libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[pepper=00000000000000000000000000000000]", + libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[key=]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, NULL, 0)); + CHECK("BLAKE2b[key=0123456789abcdef0123456789ABCDEF]", libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT, 16)); + CHECK("BLAKE2b[key=0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF]", + libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT SALT, 32)); + CHECK("BLAKE2b[key=0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF" + "0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF]", + libhashsum_init_blake2b_hasher(&hasher, 0, NULL, NULL, SALT SALT, 64)); #undef CHECK #undef SALT + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[]sum") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[]sum") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=00zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=000zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=00z0zzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == -1); + ASSERT(errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=00000000]") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE256[salt=1234567890abcdef1234567890abcdef" "1234567890abcdef1234567890abcdef]")); @@ -658,6 +730,7 @@ main(void) ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[n=0]") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[n=1000,]") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "SHAKE128[,n=1000]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "shake128[]sum") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "X") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[") == -1 && errno == EINVAL); @@ -667,6 +740,46 @@ main(void) ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[c=0]") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[n=0]") == -1 && errno == EINVAL); ASSERT(libhashsum_init_hasher_from_string(&hasher, "Keccak[z=0]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[n=0]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[n=0]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=00000000000000]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=000000000000000000000000000000]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=000000000000000000]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=0000000000000000000000000000000000]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[pepper=00000000000000]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[pepper=000000000000000000000000000000]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[pepper=000000000000000000]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[pepper=0000000000000000000000000000000000]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=zzzzzzzzzzzzzzzz]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=00zzzzzzzzzzzzzz]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=00zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=000zzzzzzzzzzzzz]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=000zzzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[salt=00z0zzzzzzzzzzzz]") == -1 && errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[salt=00z0zzzzzzzzzzzzzzzzzzzzzzzzzzzz]") == -1); + ASSERT(errno == EINVAL); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2s[key=00000000000000000000000000000000" + "0000000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000]") == -1); + ASSERT(errno == EINVAL || errno == ENOSYS); + ASSERT(libhashsum_init_hasher_from_string(&hasher, "BLAKE2b[key=00000000000000000000000000000000" + "0000000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000]") == -1); + ASSERT(errno == EINVAL || errno == ENOSYS); return 0; } |