From b3e6e5deebb7ffbe68b11ab19a9090aa9494b651 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 18 Jun 2018 22:16:43 +0200 Subject: [PATCH] Rename hash max sizes for consistency Use "hash" throughout the library, not "md" as in Mbed TLS. --- include/psa/crypto_struct.h | 10 +++---- library/psa_crypto.c | 33 +-------------------- tests/suites/test_suite_psa_crypto.function | 3 +- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index 4b0f9799b..0dbd86c18 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -46,11 +46,11 @@ #include "mbedtls/sha512.h" #if defined(MBEDTLS_SHA512_C) -#define PSA_CRYPTO_MD_MAX_SIZE 64 -#define PSA_CRYPTO_MD_BLOCK_SIZE 128 +#define PSA_HASH_MAX_SIZE 64 +#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128 #else -#define PSA_CRYPTO_MD_MAX_SIZE 32 -#define PSA_CRYPTO_MD_BLOCK_SIZE 64 +#define PSA_HASH_MAX_SIZE 32 +#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64 #endif struct psa_hash_operation_s @@ -89,7 +89,7 @@ typedef struct /** The hash context. */ struct psa_hash_operation_s hash_ctx; /** The HMAC part of the context. */ - uint8_t opad[PSA_CRYPTO_MD_BLOCK_SIZE]; + uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE]; } psa_hmac_internal_data; diff --git a/library/psa_crypto.c b/library/psa_crypto.c index e5ac7bd81..446c90ea0 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -614,37 +614,6 @@ static const mbedtls_md_info_t *mbedtls_md_info_from_psa( psa_algorithm_t alg ) } } -#if 0 -static psa_algorithm_t mbedtls_md_alg_to_psa( mbedtls_md_type_t md_alg ) -{ - switch( md_alg ) - { - case MBEDTLS_MD_NONE: - return( 0 ); - case MBEDTLS_MD_MD2: - return( PSA_ALG_MD2 ); - case MBEDTLS_MD_MD4: - return( PSA_ALG_MD4 ); - case MBEDTLS_MD_MD5: - return( PSA_ALG_MD5 ); - case MBEDTLS_MD_SHA1: - return( PSA_ALG_SHA_1 ); - case MBEDTLS_MD_SHA224: - return( PSA_ALG_SHA_224 ); - case MBEDTLS_MD_SHA256: - return( PSA_ALG_SHA_256 ); - case MBEDTLS_MD_SHA384: - return( PSA_ALG_SHA_384 ); - case MBEDTLS_MD_SHA512: - return( PSA_ALG_SHA_512 ); - case MBEDTLS_MD_RIPEMD160: - return( PSA_ALG_RIPEMD160 ); - default: - return( 0 ); - } -} -#endif - psa_status_t psa_hash_abort( psa_hash_operation_t *operation ) { switch( operation->alg ) @@ -1081,7 +1050,7 @@ static int psa_hmac_start( psa_mac_operation_t *operation, key_slot_t *slot, psa_algorithm_t alg ) { - unsigned char ipad[PSA_CRYPTO_MD_BLOCK_SIZE]; + unsigned char ipad[PSA_HMAC_MAX_HASH_BLOCK_SIZE]; unsigned char *opad = operation->ctx.hmac.opad; size_t i; size_t block_size = diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index a88e02fd7..69deba11e 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -1,7 +1,6 @@ /* BEGIN_HEADER */ #include #include "psa/crypto.h" -#include "mbedtls/md.h" #if(UINT32_MAX > SIZE_MAX) #define PSA_CRYPTO_TEST_SIZE_T_RANGE( x ) ( ( x ) <= SIZE_MAX ) @@ -212,7 +211,7 @@ exit: void hash_finish( int alg_arg, data_t *input, data_t *expected_hash ) { psa_algorithm_t alg = alg_arg; - unsigned char actual_hash[MBEDTLS_MD_MAX_SIZE]; + unsigned char actual_hash[PSA_HASH_MAX_SIZE]; size_t actual_hash_length; psa_hash_operation_t operation;