mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 10:55:46 +01:00
Add NIST validation tests for HMAC_DRBG nopr
This commit is contained in:
parent
4f880a5dc2
commit
24600b7c8a
@ -65,6 +65,7 @@ add_test_suite(gcm gcm.aes256_de)
|
||||
add_test_suite(gcm gcm.camellia)
|
||||
add_test_suite(hmac_drbg hmac_drbg.misc)
|
||||
add_test_suite(hmac_drbg hmac_drbg.no_reseed)
|
||||
add_test_suite(hmac_drbg hmac_drbg.nopr)
|
||||
add_test_suite(hmac_shax)
|
||||
add_test_suite(md)
|
||||
add_test_suite(mdx)
|
||||
|
@ -46,6 +46,7 @@ APPS = test_suite_aes.ecb test_suite_aes.cbc \
|
||||
test_suite_gcm.camellia test_suite_hmac_shax \
|
||||
test_suite_hmac_drbg.misc \
|
||||
test_suite_hmac_drbg.no_reseed \
|
||||
test_suite_hmac_drbg.nopr \
|
||||
test_suite_md test_suite_mdx \
|
||||
test_suite_mpi test_suite_pbkdf2 \
|
||||
test_suite_pkcs1_v21 test_suite_pkcs5 \
|
||||
@ -143,6 +144,10 @@ test_suite_hmac_drbg.no_reseed.c : suites/test_suite_hmac_drbg.function suites/t
|
||||
echo " Generate $@"
|
||||
scripts/generate_code.pl suites test_suite_hmac_drbg test_suite_hmac_drbg.no_reseed
|
||||
|
||||
test_suite_hmac_drbg.nopr.c : suites/test_suite_hmac_drbg.function suites/test_suite_hmac_drbg.nopr.data scripts/generate_code.pl suites/helpers.function suites/main_test.function
|
||||
echo " Generate $@"
|
||||
scripts/generate_code.pl suites test_suite_hmac_drbg test_suite_hmac_drbg.nopr
|
||||
|
||||
%.c : suites/%.function suites/%.data scripts/generate_code.pl suites/helpers.function suites/main_test.function
|
||||
echo " Generate $@"
|
||||
scripts/generate_code.pl suites $* $*
|
||||
@ -275,6 +280,10 @@ test_suite_hmac_drbg.no_reseed: test_suite_hmac_drbg.no_reseed.c ../library/libp
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
||||
test_suite_hmac_drbg.nopr: test_suite_hmac_drbg.nopr.c ../library/libpolarssl.a
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
||||
test_suite_hmac_shax: test_suite_hmac_shax.c ../library/libpolarssl.a
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
@ -182,14 +182,50 @@ void hmac_drbg_no_reseed( int md_alg,
|
||||
add2, add2_len ) == 0 );
|
||||
hmac_drbg_free( &ctx );
|
||||
|
||||
/* Check output is correct */
|
||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||
|
||||
/* Check we didn't write more bytes than needed */
|
||||
TEST_ASSERT( my_output[out_len + 0] == 0 );
|
||||
TEST_ASSERT( my_output[out_len + 1] == 0 );
|
||||
TEST_ASSERT( my_output[out_len + 2] == 0 );
|
||||
TEST_ASSERT( my_output[out_len + 3] == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_nopr( int md_alg,
|
||||
char *entropy_hex, char *custom_hex,
|
||||
char *add1_hex, char *add2_hex, char *add3_hex,
|
||||
char *output_hex )
|
||||
{
|
||||
unsigned char entropy[512];
|
||||
unsigned char custom[512];
|
||||
unsigned char add1[512];
|
||||
unsigned char add2[512];
|
||||
unsigned char add3[512];
|
||||
unsigned char output[512];
|
||||
unsigned char my_output[512];
|
||||
size_t custom_len, add1_len, add2_len, add3_len, out_len;
|
||||
entropy_ctx p_entropy;
|
||||
const md_info_t *md_info;
|
||||
hmac_drbg_context ctx;
|
||||
|
||||
memset( my_output, 0, sizeof my_output );
|
||||
|
||||
custom_len = unhexify( custom, custom_hex );
|
||||
add1_len = unhexify( add1, add1_hex );
|
||||
add2_len = unhexify( add2, add2_hex );
|
||||
add3_len = unhexify( add3, add3_hex );
|
||||
out_len = unhexify( output, output_hex );
|
||||
p_entropy.len = unhexify( entropy, entropy_hex );
|
||||
p_entropy.p = entropy;
|
||||
|
||||
TEST_ASSERT( ( md_info = md_info_from_type( md_alg ) ) != NULL );
|
||||
TEST_ASSERT( hmac_drbg_init( &ctx, md_info, entropy_func, &p_entropy,
|
||||
custom, custom_len ) == 0 );
|
||||
TEST_ASSERT( hmac_drbg_reseed( &ctx, add1, add1_len ) == 0 );
|
||||
TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add2, add2_len ) == 0 );
|
||||
TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add3, add3_len ) == 0 );
|
||||
hmac_drbg_free( &ctx );
|
||||
|
||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
1200
tests/suites/test_suite_hmac_drbg.nopr.data
Normal file
1200
tests/suites/test_suite_hmac_drbg.nopr.data
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user