crypto: Adapt kdf_t interface to support KDFs with fixed output length
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user