Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 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 | |
Valerio Setti | c1db99d | 2023-12-12 11:19:17 +0100 | [diff] [blame] | 27 | #if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA) |
Valerio Setti | 849a1ab | 2023-12-13 16:34:07 +0100 | [diff] [blame] | 28 | #include "psa/crypto_types.h" |
Valerio Setti | c1db99d | 2023-12-12 11:19:17 +0100 | [diff] [blame] | 29 | #endif |
| 30 | |
Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 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 | |
Valerio Setti | c1db99d | 2023-12-12 11:19:17 +0100 | [diff] [blame] | 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 | |
Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 52 | typedef struct { |
| 53 | mbedtls_block_cipher_id_t MBEDTLS_PRIVATE(id); |
Valerio Setti | c1db99d | 2023-12-12 11:19:17 +0100 | [diff] [blame] | 54 | #if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA) |
Valerio Setti | 291571b | 2023-12-13 16:41:19 +0100 | [diff] [blame] | 55 | mbedtls_block_cipher_engine_t MBEDTLS_PRIVATE(engine); |
Valerio Setti | 291571b | 2023-12-13 16:41:19 +0100 | [diff] [blame] | 56 | mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psa_key_id); |
Valerio Setti | c1db99d | 2023-12-12 11:19:17 +0100 | [diff] [blame] | 57 | #endif |
Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 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 */ |