From e6cdbbd40ba3fa7646c0415a53ae3729511ffa80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Sat, 1 Feb 2014 11:30:03 +0100 Subject: [PATCH] Add tests for th init_buf() variant of HMAC_DRBG --- tests/suites/test_suite_hmac_drbg.function | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/suites/test_suite_hmac_drbg.function b/tests/suites/test_suite_hmac_drbg.function index 0882696d0e..d9a365d0f9 100644 --- a/tests/suites/test_suite_hmac_drbg.function +++ b/tests/suites/test_suite_hmac_drbg.function @@ -153,6 +153,7 @@ void hmac_drbg_no_reseed( int md_alg, char *add1_hex, char *add2_hex, char *output_hex ) { + unsigned char data[1024]; unsigned char entropy[512]; unsigned char custom[512]; unsigned char add1[512]; @@ -174,6 +175,21 @@ void hmac_drbg_no_reseed( int md_alg, p_entropy.p = entropy; TEST_ASSERT( ( md_info = md_info_from_type( md_alg ) ) != NULL ); + + /* Test the simplified buffer-based variant */ + memcpy( data, entropy, p_entropy.len ); + memcpy( data + p_entropy.len, custom, custom_len ); + TEST_ASSERT( hmac_drbg_init_buf( &ctx, md_info, + data, p_entropy.len + custom_len ) == 0 ); + TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len, + add1, add1_len ) == 0 ); + TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len, + add2, add2_len ) == 0 ); + hmac_drbg_free( &ctx ); + + TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 ); + + /* And now the normal entropy-based variant */ TEST_ASSERT( hmac_drbg_init( &ctx, md_info, entropy_func, &p_entropy, custom, custom_len ) == 0 ); TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len, @@ -183,6 +199,7 @@ void hmac_drbg_no_reseed( int md_alg, hmac_drbg_free( &ctx ); TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 ); + } /* END_CASE */