From 42fd888ab09c1aa32c7b20bd3ac8f6b7ea618f4f Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Wed, 3 Jul 2019 14:17:09 +0100 Subject: [PATCH] Convert derive_key_export to the new KDF API --- tests/suites/test_suite_psa_crypto.data | 8 +++---- tests/suites/test_suite_psa_crypto.function | 24 +++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data index 11d61d4b34..cf1911fc88 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -2055,12 +2055,12 @@ PSA key derivation: TLS 1.2 PRF SHA-256, exercise HKDF-SHA-256 depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C:!PSA_PRE_1_0_KEY_DERIVATION derive_key_exercise:PSA_ALG_TLS12_PRF(PSA_ALG_SHA_256):"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"000102030405060708090a0b0c":"f0f1f2f3f4f5f6f7f8f9":PSA_KEY_TYPE_DERIVE:400:PSA_KEY_USAGE_DERIVE:PSA_ALG_HKDF(PSA_ALG_SHA_256) -PSA key derivation: HKDF SHA-256, derive key, 16+32 -depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C +PSA key derivation: HKDF SHA-256, derive key export, 16+32 +depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C:!PSA_PRE_1_0_KEY_DERIVATION derive_key_export:PSA_ALG_HKDF(PSA_ALG_SHA_256):"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"000102030405060708090a0b0c":"f0f1f2f3f4f5f6f7f8f9":16:32 -PSA key derivation: HKDF SHA-256, derive key, 1+41 -depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C +PSA key derivation: HKDF SHA-256, derive key export, 1+41 +depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C:!PSA_PRE_1_0_KEY_DERIVATION derive_key_export:PSA_ALG_HKDF(PSA_ALG_SHA_256):"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"000102030405060708090a0b0c":"f0f1f2f3f4f5f6f7f8f9":1:41 PSA key agreement setup: ECDH + HKDF-SHA-256: good diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index a36a8aff59..a6fcdb5c29 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -4480,11 +4480,11 @@ exit: } /* END_CASE */ -/* BEGIN_CASE depends_on:PSA_PRE_1_0_KEY_DERIVATION */ +/* BEGIN_CASE */ void derive_key_export( int alg_arg, data_t *key_data, - data_t *salt, - data_t *label, + data_t *input1, + data_t *input2, int bytes1_arg, int bytes2_arg ) { @@ -4512,20 +4512,22 @@ void derive_key_export( int alg_arg, &base_handle ) ); /* Derive some material and output it. */ - PSA_ASSERT( psa_key_derivation( &operation, base_handle, alg, - salt->x, salt->len, - label->x, label->len, - capacity ) ); + if( !setup_key_derivation_wrap( &operation, base_handle, alg, + input1->x, input1->len, + input2->x, input2->len, capacity ) ) + goto exit; + PSA_ASSERT( psa_key_derivation_output_bytes( &operation, output_buffer, capacity ) ); PSA_ASSERT( psa_key_derivation_abort( &operation ) ); /* Derive the same output again, but this time store it in key objects. */ - PSA_ASSERT( psa_key_derivation( &operation, base_handle, alg, - salt->x, salt->len, - label->x, label->len, - capacity ) ); + if( !setup_key_derivation_wrap( &operation, base_handle, alg, + input1->x, input1->len, + input2->x, input2->len, capacity ) ) + goto exit; + psa_set_key_usage_flags( &derived_attributes, PSA_KEY_USAGE_EXPORT ); psa_set_key_algorithm( &derived_attributes, 0 ); psa_set_key_type( &derived_attributes, PSA_KEY_TYPE_RAW_DATA );