Skip to content

Commit e1a8187

Browse files
committed
pk_wrap: pass curve size instead of a larger size of the exported key
Whitespace fixes
1 parent 1ec0fee commit e1a8187

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

include/mbedtls/psa_util.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ static inline psa_ecc_curve_t mbedtls_psa_translate_ecc_group( mbedtls_ecp_group
216216
}
217217
}
218218

219+
#define MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( curve ) \
220+
( curve == PSA_ECC_CURVE_SECP192R1 ? 192 : \
221+
curve == PSA_ECC_CURVE_SECP224R1 ? 224 : \
222+
curve == PSA_ECC_CURVE_SECP256R1 ? 256 : \
223+
curve == PSA_ECC_CURVE_SECP384R1 ? 384 : \
224+
curve == PSA_ECC_CURVE_SECP521R1 ? 521 : \
225+
curve == PSA_ECC_CURVE_SECP192K1 ? 192 : \
226+
curve == PSA_ECC_CURVE_SECP224K1 ? 224 : \
227+
curve == PSA_ECC_CURVE_SECP256K1 ? 256 : \
228+
curve == PSA_ECC_CURVE_BRAINPOOL_P256R1 ? 256 : \
229+
curve == PSA_ECC_CURVE_BRAINPOOL_P384R1 ? 384 : \
230+
curve == PSA_ECC_CURVE_BRAINPOOL_P512R1 ? 512 : \
231+
0 )
232+
233+
#define MBEDTLS_PSA_ECC_KEY_BYTES_OF_CURVE( curve ) \
234+
( ( MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( curve ) + 7 ) / 8 )
235+
219236
/* Translations for PK layer */
220237

221238
static inline int mbedtls_psa_err_translate_pk( psa_status_t status )

library/pk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk,
573573

574574
curve_id = mbedtls_ecp_curve_info_from_grp_id( ec->grp.id )->tls_id;
575575
key_type = PSA_KEY_TYPE_ECC_KEYPAIR(
576-
mbedtls_psa_parse_tls_ecc_group ( curve_id ) );
576+
mbedtls_psa_parse_tls_ecc_group ( curve_id ) );
577577

578578
/* allocate a key slot */
579579
if( PSA_SUCCESS != psa_allocate_key( key_type, d_len * 8, &key ) )

library/pk_wrap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
577577
psa_sig_md = PSA_ALG_ECDSA( psa_md );
578578
psa_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY( curve );
579579

580-
if( ( ret = psa_allocate_key( psa_type, key_len * 8, &key_slot ) ) != PSA_SUCCESS )
580+
if( ( ret = psa_allocate_key( psa_type,
581+
MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE(curve),
582+
&key_slot ) ) != PSA_SUCCESS )
581583
return( mbedtls_psa_err_translate_pk( ret ) );
582584

583585
psa_key_policy_init( &policy );

0 commit comments

Comments
 (0)