1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Increase generichash test coverage

This commit is contained in:
Frank Denis 2014-09-16 14:44:38 -07:00
parent 671ee78ce2
commit e333e55209
7 changed files with 142 additions and 4 deletions

View File

@ -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 )
{

View File

@ -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;
}

View File

@ -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);

View File

@ -62,3 +62,5 @@ cc66a891768e95a2717b040c111996f14942f10f2475c33aa5f1c97476e6f8386733d6b21c16102d
9ff11c233aaf5e0242b0dbe6e110a42e58b86141ad0ef130fd2bb895700019782de66d435bf0a8d6f5eda5d7d1105e7a6f3ef17a9da8f9c16fc21075431a
bdd3d0fafe8ba2b29d1ac0b79aa46e249cc9d3a82d0f772d690637bbdd353722356658d00436ff5dd5239ab747979329345eb8c7ed11b7331456ae87350fcf
bd965bf31e87d70327536f2a341cebc4768eca275fa05ef98f7f1b71a0351298de006fba73fe6733ed01d75801b4a928e54231b38e38c562b2e33ea1284992fa
2fc6e69fa26a89a5ed269092cb9b2a449a4409a7a44011eecad13d7c4b0456602d402fa5844f1a7a758136ce3d5d8d0e8b86921ffff4f692dd95bdc8e5ff0052
2fc6e69fa26a89a5ed269092cb9b2a449a4409a7a44011eecad13d7c4b0456602d402fa5844f1a7a758136ce3d5d8d0e8b86921ffff4f692dd95bdc8e5ff0052

View File

@ -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;
}

View File

@ -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;
}

View File

@ -62,3 +62,12 @@ c6d6722a916651a8671383d8260873347d9c248696b4cb3dac4dea9ba57ed971127cb18e44211d7e
5dd258a3e7505bc6b9776b0df25676a1c19e2c8258c7b5f2e361423523d96299eb6827bc7c27e7bca2d2b59d717c2ebcb05e6dcaa32289d96fae9a4077ef
19c14de35fe19c92cc0e624280e4136355d4cfa9a0a98b090c4b06f5665021920725852ff1f566b0c8c37157b25fb9f947a2e70b40577a17860a0732c170ac
5fcdcc02be7714a0dbc77df498bf999ea9225d564adca1c121c9af03af92cac8177b9b4a86bcc47c79aa32aac58a3fef967b2132e9352d4613fe890beed2571b
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
5789f474edd5206ededaccfc35e7dd3ed730748125b5395abf802b2601126b19b109a1db67556945bc79bb25e1ab59610599d155070e0e04354f11a6a5d6f3ac
e78efc663a5547c089f2b3b08973c974c4bfd365eac18b80c68bdb3b1ba4554b54d6b8465a68a3b9aa0bc020621f16efd5b8dd8c7c01ed9ee3ec5544aae465ff
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
1afc8ec818bef0a479d2b4cac81d40a52cafa27f6d80c42fc23cbaf4141882ab59ab1101922fcb6e707ef2f61efd07cce5d09094e6bee420b1b96998c7cee96d
fb4e2ad6b7fe6afd2ba06d5c1d79379c5bf10e336a35c89a1aaf408a805171716e0635a5b1d18190131e15b6888510bcb3e3752b050f892a09dbbde60b051495
5789f474edd5206ededaccfc35e7dd3ed730748125b5395abf802b2601126b19b109a1db67556945bc79bb25e1ab59610599d155070e0e04354f11a6a5d6f3ac
e78efc663a5547c089f2b3b08973c974c4bfd365eac18b80c68bdb3b1ba4554b54d6b8465a68a3b9aa0bc020621f16efd5b8dd8c7c01ed9ee3ec5544aae465ff