From 23650286ac8cbc0e278d0252b09017cc1570c880 Mon Sep 17 00:00:00 2001 From: Przemek Stekiel Date: Thu, 7 Apr 2022 13:42:59 +0200 Subject: [PATCH] Add psa_tls12_prf_set_other_key() function to store other secret input Signed-off-by: Przemek Stekiel --- library/psa_crypto.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index b2c21528c3..8c58ff518c 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5219,6 +5219,28 @@ static psa_status_t psa_tls12_prf_set_key( psa_tls12_prf_key_derivation_t *prf, return( PSA_SUCCESS ); } +static psa_status_t psa_tls12_prf_set_other_key( psa_tls12_prf_key_derivation_t *prf, + const uint8_t *data, + size_t data_length ) +{ + if( prf->state != PSA_TLS12_PRF_STATE_SEED_SET ) + return( PSA_ERROR_BAD_STATE ); + + if( data_length != 0 ) + { + prf->other_secret = mbedtls_calloc( 1, data_length ); + if( prf->other_secret == NULL ) + return( PSA_ERROR_INSUFFICIENT_MEMORY ); + + memcpy( prf->other_secret, data, data_length ); + prf->other_secret_length = data_length; + } + + prf->state = PSA_TLS12_PRF_STATE_OTHER_KEY_SET; + + return( PSA_SUCCESS ); +} + static psa_status_t psa_tls12_prf_set_label( psa_tls12_prf_key_derivation_t *prf, const uint8_t *data, size_t data_length ) @@ -5252,6 +5274,8 @@ static psa_status_t psa_tls12_prf_input( psa_tls12_prf_key_derivation_t *prf, return( psa_tls12_prf_set_seed( prf, data, data_length ) ); case PSA_KEY_DERIVATION_INPUT_SECRET: return( psa_tls12_prf_set_key( prf, data, data_length ) ); + case PSA_KEY_DERIVATION_INPUT_OTHER_SECRET: + return( psa_tls12_prf_set_other_key( prf, data, data_length ) ); case PSA_KEY_DERIVATION_INPUT_LABEL: return( psa_tls12_prf_set_label( prf, data, data_length ) ); default: