From e333e55209bf67f65136a2233269b650a7b5e3e2 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 16 Sep 2014 14:44:38 -0700 Subject: [PATCH] Increase generichash test coverage --- .../blake2/ref/blake2b-ref.c | 2 + .../blake2/ref/generichash_blake2b.c | 8 +- test/default/generichash.c | 14 +++ test/default/generichash.exp | 2 + test/default/generichash2.c | 7 ++ test/default/generichash3.c | 104 ++++++++++++++++++ test/default/generichash3.exp | 9 ++ 7 files changed, 142 insertions(+), 4 deletions(-) diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c index b07ad228..2610477d 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c @@ -43,11 +43,13 @@ static const uint8_t blake2b_sigma[12][16] = }; +/* LCOV_EXCL_START */ static inline int blake2b_set_lastnode( blake2b_state *S ) { S->f[1] = ~0ULL; return 0; } +/* LCOV_EXCL_STOP */ #if 0 static inline int blake2b_clear_lastnode( blake2b_state *S ) { diff --git a/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c b/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c index 6a637eca..7253cbf3 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c +++ b/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c @@ -54,11 +54,11 @@ crypto_generichash_blake2b_init(crypto_generichash_blake2b_state *state, assert(keylen <= UINT8_MAX); if (key == NULL || keylen <= 0U) { if (blake2b_init(state, (uint8_t) outlen) != 0) { - return -1; + return -1; /* LCOV_EXCL_LINE */ } } else if (blake2b_init_key(state, (uint8_t) outlen, key, (uint8_t) keylen) != 0) { - return -1; + return -1; /* LCOV_EXCL_LINE */ } return 0; } @@ -79,13 +79,13 @@ crypto_generichash_blake2b_init_salt_personal(crypto_generichash_blake2b_state * if (key == NULL || keylen <= 0U) { if (blake2b_init_salt_personal(state, (uint8_t) outlen, salt, personal) != 0) { - return -1; + return -1; /* LCOV_EXCL_LINE */ } } else if (blake2b_init_key_salt_personal(state, (uint8_t) outlen, key, (uint8_t) keylen, salt, personal) != 0) { - return -1; + return -1; /* LCOV_EXCL_LINE */ } return 0; } diff --git a/test/default/generichash.c b/test/default/generichash.c index a560d90a..71c12e44 100644 --- a/test/default/generichash.c +++ b/test/default/generichash.c @@ -22,6 +22,20 @@ int main(void) printf("\n"); } + memset(out, 0, sizeof out); + crypto_generichash(out, crypto_generichash_BYTES_MAX, in, i, k, 0U); + for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash(out, crypto_generichash_BYTES_MAX, in, i, NULL, 1U); + for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + assert(crypto_generichash(out, 0U, in, sizeof in, k, sizeof k) == -1); assert(crypto_generichash(out, crypto_generichash_BYTES_MAX + 1U, in, sizeof in, k, sizeof k) == -1); diff --git a/test/default/generichash.exp b/test/default/generichash.exp index 1840ff24..4a918f91 100644 --- a/test/default/generichash.exp +++ b/test/default/generichash.exp @@ -62,3 +62,5 @@ cc66a891768e95a2717b040c111996f14942f10f2475c33aa5f1c97476e6f8386733d6b21c16102d 9ff11c233aaf5e0242b0dbe6e110a42e58b86141ad0ef130fd2bb895700019782de66d435bf0a8d6f5eda5d7d1105e7a6f3ef17a9da8f9c16fc21075431a bdd3d0fafe8ba2b29d1ac0b79aa46e249cc9d3a82d0f772d690637bbdd353722356658d00436ff5dd5239ab747979329345eb8c7ed11b7331456ae87350fcf bd965bf31e87d70327536f2a341cebc4768eca275fa05ef98f7f1b71a0351298de006fba73fe6733ed01d75801b4a928e54231b38e38c562b2e33ea1284992fa +2fc6e69fa26a89a5ed269092cb9b2a449a4409a7a44011eecad13d7c4b0456602d402fa5844f1a7a758136ce3d5d8d0e8b86921ffff4f692dd95bdc8e5ff0052 +2fc6e69fa26a89a5ed269092cb9b2a449a4409a7a44011eecad13d7c4b0456602d402fa5844f1a7a758136ce3d5d8d0e8b86921ffff4f692dd95bdc8e5ff0052 diff --git a/test/default/generichash2.c b/test/default/generichash2.c index 81480ca9..e1b6a9a9 100644 --- a/test/default/generichash2.c +++ b/test/default/generichash2.c @@ -33,5 +33,12 @@ int main(void) crypto_generichash_BYTES_MAX + 1U) == -1); assert(crypto_generichash_init(&st, k, crypto_generichash_KEYBYTES_MAX + 1U, sizeof out) == -1); + 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); return 0; } diff --git a/test/default/generichash3.c b/test/default/generichash3.c index 29ffd61e..3ea55dde 100644 --- a/test/default/generichash3.c +++ b/test/default/generichash3.c @@ -32,6 +32,100 @@ int main(void) } printf("\n"); } + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_init_salt_personal( + &st, k, 0U, crypto_generichash_blake2b_BYTES_MAX, salt, personal); + crypto_generichash_blake2b_update(&st, in, MAXLEN); + crypto_generichash_blake2b_final(&st, out, + crypto_generichash_blake2b_BYTES_MAX); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_init_salt_personal( + &st, NULL, 1U, crypto_generichash_blake2b_BYTES_MAX, salt, personal); + crypto_generichash_blake2b_update(&st, in, MAXLEN); + crypto_generichash_blake2b_final(&st, out, + crypto_generichash_blake2b_BYTES_MAX); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_init_salt_personal( + &st, k, crypto_generichash_blake2b_KEYBYTES_MAX, + crypto_generichash_blake2b_BYTES_MAX, NULL, personal); + crypto_generichash_blake2b_update(&st, in, MAXLEN); + crypto_generichash_blake2b_final(&st, out, + crypto_generichash_blake2b_BYTES_MAX); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_init_salt_personal( + &st, k, crypto_generichash_blake2b_KEYBYTES_MAX, + crypto_generichash_blake2b_BYTES_MAX, salt, NULL); + crypto_generichash_blake2b_update(&st, in, MAXLEN); + assert(crypto_generichash_blake2b_final( + &st, out, crypto_generichash_blake2b_BYTES_MAX + 1U) == -1); + crypto_generichash_blake2b_final( + &st, out, crypto_generichash_blake2b_BYTES_MAX); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_salt_personal( + out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN, + k, 0U, salt, personal); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_salt_personal( + out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN, + NULL, crypto_generichash_blake2b_KEYBYTES_MAX, salt, personal); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_salt_personal( + out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN, + k, crypto_generichash_blake2b_KEYBYTES_MAX, salt, personal); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_salt_personal( + out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN, + k, crypto_generichash_blake2b_KEYBYTES_MAX, NULL, personal); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + + memset(out, 0, sizeof out); + crypto_generichash_blake2b_salt_personal( + out, crypto_generichash_blake2b_BYTES_MAX, in, MAXLEN, + k, crypto_generichash_blake2b_KEYBYTES_MAX, salt, NULL); + for (j = 0; j < crypto_generichash_blake2b_BYTES_MAX; ++j) { + printf("%02x", (unsigned int)out[j]); + } + printf("\n"); + assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, 0U, salt, personal) == -1); assert(crypto_generichash_blake2b_init_salt_personal(&st, k, sizeof k, @@ -40,5 +134,15 @@ int main(void) assert(crypto_generichash_blake2b_init_salt_personal(&st, k, crypto_generichash_KEYBYTES_MAX + 1U, sizeof out, salt, personal) == -1); + + assert(crypto_generichash_blake2b_salt_personal(out, 0U, in, MAXLEN, + k, sizeof k, + salt, personal) == -1); + assert(crypto_generichash_blake2b_salt_personal(out, crypto_generichash_BYTES_MAX + 1U, + in, MAXLEN, k, sizeof k, + salt, personal) == -1); + assert(crypto_generichash_blake2b_salt_personal(out, sizeof out, in, MAXLEN, + k, crypto_generichash_KEYBYTES_MAX + 1U, + salt, personal) == -1); return 0; } diff --git a/test/default/generichash3.exp b/test/default/generichash3.exp index f81d8e22..d25f5f83 100644 --- a/test/default/generichash3.exp +++ b/test/default/generichash3.exp @@ -62,3 +62,12 @@ c6d6722a916651a8671383d8260873347d9c248696b4cb3dac4dea9ba57ed971127cb18e44211d7e 5dd258a3e7505bc6b9776b0df25676a1c19e2c8258c7b5f2e361423523d96299eb6827bc7c27e7bca2d2b59d717c2ebcb05e6dcaa32289d96fae9a4077ef 19c14de35fe19c92cc0e624280e4136355d4cfa9a0a98b090c4b06f5665021920725852ff1f566b0c8c37157b25fb9f947a2e70b40577a17860a0732c170ac 5fcdcc02be7714a0dbc77df498bf999ea9225d564adca1c121c9af03af92cac8177b9b4a86bcc47c79aa32aac58a3fef967b2132e9352d4613fe890beed2571b +1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d +1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d +5789f474edd5206ededaccfc35e7dd3ed730748125b5395abf802b2601126b19b109a1db67556945bc79bb25e1ab59610599d155070e0e04354f11a6a5d6f3ac +e78efc663a5547c089f2b3b08973c974c4bfd365eac18b80c68bdb3b1ba4554b54d6b8465a68a3b9aa0bc020621f16efd5b8dd8c7c01ed9ee3ec5544aae465ff +1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d +1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d +fb4e2ad6b7fe6afd2ba06d5c1d79379c5bf10e336a35c89a1aaf408a805171716e0635a5b1d18190131e15b6888510bcb3e3752b050f892a09dbbde60b051495 +5789f474edd5206ededaccfc35e7dd3ed730748125b5395abf802b2601126b19b109a1db67556945bc79bb25e1ab59610599d155070e0e04354f11a6a5d6f3ac +e78efc663a5547c089f2b3b08973c974c4bfd365eac18b80c68bdb3b1ba4554b54d6b8465a68a3b9aa0bc020621f16efd5b8dd8c7c01ed9ee3ec5544aae465ff