1 /** 2 * \file block_cipher.h 3 * 4 * \brief Internal abstraction layer. 5 */ 6 /* 7 * Copyright The Mbed TLS Contributors 8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 9 */ 10 #ifndef MBEDTLS_BLOCK_CIPHER_H 11 #define MBEDTLS_BLOCK_CIPHER_H 12 13 #include "mbedtls/private_access.h" 14 15 #include "mbedtls/build_info.h" 16 17 #if defined(MBEDTLS_AES_C) 18 #include "mbedtls/aes.h" 19 #endif 20 #if defined(MBEDTLS_ARIA_C) 21 #include "mbedtls/aria.h" 22 #endif 23 #if defined(MBEDTLS_CAMELLIA_C) 24 #include "mbedtls/camellia.h" 25 #endif 26 27 #if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA) 28 #include "psa/crypto_types.h" 29 #endif 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 typedef enum { 36 MBEDTLS_BLOCK_CIPHER_ID_NONE = 0, /**< Unset. */ 37 MBEDTLS_BLOCK_CIPHER_ID_AES, /**< The AES cipher. */ 38 MBEDTLS_BLOCK_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */ 39 MBEDTLS_BLOCK_CIPHER_ID_ARIA, /**< The Aria cipher. */ 40 } mbedtls_block_cipher_id_t; 41 42 /** 43 * Used internally to indicate whether a context uses legacy or PSA. 44 * 45 * Internal use only. 46 */ 47 typedef enum { 48 MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY = 0, 49 MBEDTLS_BLOCK_CIPHER_ENGINE_PSA, 50 } mbedtls_block_cipher_engine_t; 51 52 typedef struct { 53 mbedtls_block_cipher_id_t MBEDTLS_PRIVATE(id); 54 #if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA) 55 mbedtls_block_cipher_engine_t MBEDTLS_PRIVATE(engine); 56 mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psa_key_id); 57 #endif 58 union { 59 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ 60 #if defined(MBEDTLS_AES_C) 61 mbedtls_aes_context MBEDTLS_PRIVATE(aes); 62 #endif 63 #if defined(MBEDTLS_ARIA_C) 64 mbedtls_aria_context MBEDTLS_PRIVATE(aria); 65 #endif 66 #if defined(MBEDTLS_CAMELLIA_C) 67 mbedtls_camellia_context MBEDTLS_PRIVATE(camellia); 68 #endif 69 } MBEDTLS_PRIVATE(ctx); 70 } mbedtls_block_cipher_context_t; 71 72 #ifdef __cplusplus 73 } 74 #endif 75 76 #endif /* MBEDTLS_BLOCK_CIPHER_H */ 77