crypto: Adapt kdf_t interface to support KDFs with fixed output length

This commit is contained in:
Tobias Brunner
2022-04-14 19:02:56 +02:00
parent 96c7692661
commit 7bde56a9bc
7 changed files with 89 additions and 1 deletions
+24
View File
@@ -1309,6 +1309,17 @@ METHOD(crypto_tester_t, test_kdf, bool,
{
goto failure;
}
if (kdf_has_fixed_output_length(alg))
{
if (kdf->get_length(kdf) != vector->out.len)
{
goto failure;
}
}
else if (kdf->get_length(kdf) != SIZE_MAX)
{
goto failure;
}
/* allocated bytes */
if (!kdf->allocate_bytes(kdf, vector->out.len, &out))
{
@@ -1318,6 +1329,19 @@ METHOD(crypto_tester_t, test_kdf, bool,
{
goto failure;
}
/* allocate without knowing the length */
if (kdf_has_fixed_output_length(alg))
{
chunk_free(&out);
if (!kdf->allocate_bytes(kdf, 0, &out))
{
goto failure;
}
if (!chunk_equals(out, vector->out))
{
goto failure;
}
}
/* bytes to existing buffer */
memset(out.ptr, 0, out.len);
if (!kdf->get_bytes(kdf, out.len, out.ptr))