1 /* 2 * Context structure declaration of the Mbed TLS software-based PSA drivers 3 * called through the PSA Crypto driver dispatch layer. 4 * This file contains the context structures of those algorithms which need to 5 * rely on other algorithms, i.e. are 'composite' algorithms. 6 * 7 * \note This file may not be included directly. Applications must 8 * include psa/crypto.h. 9 * 10 * \note This header and its content is not part of the Mbed TLS API and 11 * applications must not depend on it. Its main purpose is to define the 12 * multi-part state objects of the Mbed TLS software-based PSA drivers. The 13 * definition of these objects are then used by crypto_struct.h to define the 14 * implementation-defined types of PSA multi-part state objects. 15 */ 16 /* 17 * Copyright The Mbed TLS Contributors 18 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 19 */ 20 21 #ifndef PSA_CRYPTO_BUILTIN_COMPOSITES_H 22 #define PSA_CRYPTO_BUILTIN_COMPOSITES_H 23 24 #include <psa/crypto_driver_common.h> 25 26 /* 27 * MAC multi-part operation definitions. 28 */ 29 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \ 30 defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) 31 #define MBEDTLS_PSA_BUILTIN_MAC 32 #endif 33 34 #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) || \ 35 defined(MBEDTLS_PSA_BUILTIN_ALG_CCM) || \ 36 defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305) 37 #define MBEDTLS_PSA_BUILTIN_AEAD 1 38 #endif 39 40 #if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST) 41 typedef struct { 42 /** The HMAC algorithm in use */ 43 psa_algorithm_t alg; 44 /** The hash context. */ 45 struct psa_hash_operation_s hash_ctx; 46 /** The HMAC part of the context. */ 47 uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE]; 48 } mbedtls_psa_hmac_operation_t; 49 50 #define MBEDTLS_PSA_HMAC_OPERATION_INIT { 0, PSA_HASH_OPERATION_INIT, { 0 } } 51 #endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */ 52 53 #include "mbedtls/cmac.h" 54 55 typedef struct { 56 psa_algorithm_t alg; 57 union { 58 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ 59 #if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST) 60 mbedtls_psa_hmac_operation_t hmac; 61 #endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */ 62 #if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || defined(PSA_CRYPTO_DRIVER_TEST) 63 mbedtls_cipher_context_t cmac; 64 #endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */ 65 } ctx; 66 } mbedtls_psa_mac_operation_t; 67 68 #define MBEDTLS_PSA_MAC_OPERATION_INIT { 0, { 0 } } 69 70 #endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */ 71