From 11a33e6d90737f188d75421f33defad86dadde4d Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 12 Jan 2022 10:42:58 +0100 Subject: [PATCH] Use PSA_BITS_TO_BYTES macro to convert key bits to bytes Signed-off-by: Przemyslaw Stekiel --- library/ssl_tls.c | 7 ++----- library/ssl_tls13_keys.c | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 44b9c85af..0be6ec646 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -56,9 +56,6 @@ #include "mbedtls/oid.h" #endif -/* Convert key bits to byte size */ -#define KEY_BYTES( bits ) ( ( (size_t) bits + 7 ) / 8 ) - #if defined(MBEDTLS_SSL_PROTO_DTLS) #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) @@ -1106,7 +1103,7 @@ static int ssl_tls12_populate_transform( mbedtls_ssl_transform *transform, if( ( status = psa_import_key( &attributes, key1, - KEY_BYTES( key_bits ), + PSA_BITS_TO_BYTES( key_bits ), &transform->psa_key_enc ) ) != PSA_SUCCESS ) { MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status ); @@ -1114,7 +1111,7 @@ static int ssl_tls12_populate_transform( mbedtls_ssl_transform *transform, } if( ( status = psa_import_key( &attributes, key2, - KEY_BYTES( key_bits ), + PSA_BITS_TO_BYTES( key_bits ), &transform->psa_key_dec ) ) != PSA_SUCCESS ) { MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status ); diff --git a/library/ssl_tls13_keys.c b/library/ssl_tls13_keys.c index 299d8bca4..58ff010b2 100644 --- a/library/ssl_tls13_keys.c +++ b/library/ssl_tls13_keys.c @@ -31,10 +31,6 @@ #include "ssl_misc.h" #include "ssl_tls13_keys.h" -/* Convert key bits to byte size */ -#define KEY_BYTES( bits ) ( ( (size_t) bits + 7 ) / 8 ) - - #define MBEDTLS_SSL_TLS1_3_LABEL( name, string ) \ .name = string, @@ -937,7 +933,7 @@ int mbedtls_ssl_tls13_populate_transform( mbedtls_ssl_transform *transform, if( ( status = psa_import_key( &attributes, key_enc, - KEY_BYTES( key_bits ), + PSA_BITS_TO_BYTES( key_bits ), &transform->psa_key_enc ) ) != PSA_SUCCESS ) { MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status ); @@ -945,7 +941,7 @@ int mbedtls_ssl_tls13_populate_transform( mbedtls_ssl_transform *transform, } if( ( status = psa_import_key( &attributes, key_dec, - KEY_BYTES( key_bits ), + PSA_BITS_TO_BYTES( key_bits ), &transform->psa_key_dec ) ) != PSA_SUCCESS ) { MBEDTLS_SSL_DEBUG_RET( 1, "psa_import_key", status );