From 0cad07c2fb0f34b2ad8502433b0e387408e97e21 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 27 Jun 2018 19:49:02 +0200 Subject: [PATCH] New header crypto_sizes.h This header will contain macros that calculate buffer sizes, whose semantics are standardized but whose definitions are implementation-specific because they depend on the available algorithms and on some permitted buffer size tolerances. Move size macros from crypto_struct.h to crypto_sizes.h, because these definitions need to be available both in the frontend and in the backend, whereas structures have different contents. --- include/psa/crypto.h | 4 +++ include/psa/crypto_sizes.h | 50 +++++++++++++++++++++++++++++++++++++ include/psa/crypto_struct.h | 8 ------ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 include/psa/crypto_sizes.h diff --git a/include/psa/crypto.h b/include/psa/crypto.h index dcf1ba227f..8f3a7f0399 100644 --- a/include/psa/crypto.h +++ b/include/psa/crypto.h @@ -2070,6 +2070,10 @@ psa_status_t psa_generate_key(psa_key_slot_t key, } #endif +/* The file "crypto_sizes.h" contains definitions for size calculation + * macros whose definitions are implementation-specific. */ +#include "crypto_sizes.h" + /* The file "crypto_struct.h" contains definitions for * implementation-specific structs that are declared above. */ #include "crypto_struct.h" diff --git a/include/psa/crypto_sizes.h b/include/psa/crypto_sizes.h new file mode 100644 index 0000000000..1de26e6d67 --- /dev/null +++ b/include/psa/crypto_sizes.h @@ -0,0 +1,50 @@ +/** + * \file psa/crypto_sizes.h + * + * \brief PSA cryptography module: Mbed TLS buffer size macros + * + * This file contains the definitions of macros that are useful to + * compute buffer sizes. The signatures and semantics of these macros + * are standardized, but the definitions are not, because they depend on + * the available algorithms and, in some cases, on permitted tolerances + * on buffer sizes. + */ +/* + * Copyright (C) 2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#ifndef PSA_CRYPTO_SIZES_H +#define PSA_CRYPTO_SIZES_H + +/* Include the Mbed TLS configuration file, the way Mbed TLS does it + * in each of its header files. */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "../mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_SHA512_C) +#define PSA_HASH_MAX_SIZE 64 +#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128 +#else +#define PSA_HASH_MAX_SIZE 32 +#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64 +#endif + +#endif /* PSA_CRYPTO_SIZES_H */ diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index 0dbd86c18b..1935f90994 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -45,14 +45,6 @@ #include "mbedtls/sha256.h" #include "mbedtls/sha512.h" -#if defined(MBEDTLS_SHA512_C) -#define PSA_HASH_MAX_SIZE 64 -#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128 -#else -#define PSA_HASH_MAX_SIZE 32 -#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64 -#endif - struct psa_hash_operation_s { psa_algorithm_t alg;