From bf49197c9bb1b8d5086d7ee9f39ccdd1ad74da18 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 25 Oct 2018 22:36:12 +0200 Subject: [PATCH] key_agreement_capacity: test the actual capacity as well After testing that the advertized capacity is what the test data says, read that many bytes to test that this is also actual capacity. --- tests/suites/test_suite_psa_crypto.function | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 59020f7638..a0f0381070 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -3821,6 +3821,7 @@ void key_agreement_capacity( int alg_arg, psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; psa_key_policy_t policy; size_t actual_capacity; + unsigned char output[16]; TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); @@ -3836,10 +3837,25 @@ void key_agreement_capacity( int alg_arg, peer_key_data->x, peer_key_data->len, alg ) == PSA_SUCCESS ); + /* Test the advertized capacity. */ TEST_ASSERT( psa_get_generator_capacity( &generator, &actual_capacity ) == PSA_SUCCESS ); TEST_ASSERT( actual_capacity == (size_t) expected_capacity_arg ); + /* Test the actual capacity by reading the output. */ + while( actual_capacity > sizeof( output ) ) + { + TEST_ASSERT( psa_generator_read( &generator, + output, sizeof( output ) ) == + PSA_SUCCESS ); + actual_capacity -= sizeof( output ); + } + TEST_ASSERT( psa_generator_read( &generator, + output, actual_capacity ) == + PSA_SUCCESS ); + TEST_ASSERT( psa_generator_read( &generator, output, 1 ) == + PSA_ERROR_INSUFFICIENT_CAPACITY ); + exit: psa_generator_abort( &generator ); psa_destroy_key( our_key );