blob: 3f60f6f7dd4168e59e6b8d79d42687bf96465d1b [file] [log] [blame]
Manuel Pégourié-Gonnard21718762023-11-10 11:21:17 +01001/**
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 Settic1db99d2023-12-12 11:19:17 +010027#if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA)
Valerio Setti849a1ab2023-12-13 16:34:07 +010028#include "psa/crypto_types.h"
Valerio Settic1db99d2023-12-12 11:19:17 +010029#endif
30
Manuel Pégourié-Gonnard21718762023-11-10 11:21:17 +010031#ifdef __cplusplus
32extern "C" {
33#endif
34
35typedef 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 Settic1db99d2023-12-12 11:19:17 +010042/**
43 * Used internally to indicate whether a context uses legacy or PSA.
44 *
45 * Internal use only.
46 */
47typedef enum {
48 MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY = 0,
49 MBEDTLS_BLOCK_CIPHER_ENGINE_PSA,
50} mbedtls_block_cipher_engine_t;
51
Manuel Pégourié-Gonnard21718762023-11-10 11:21:17 +010052typedef struct {
53 mbedtls_block_cipher_id_t MBEDTLS_PRIVATE(id);
Valerio Settic1db99d2023-12-12 11:19:17 +010054#if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA)
Valerio Setti291571b2023-12-13 16:41:19 +010055 mbedtls_block_cipher_engine_t MBEDTLS_PRIVATE(engine);
Valerio Setti291571b2023-12-13 16:41:19 +010056 mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psa_key_id);
Valerio Settic1db99d2023-12-12 11:19:17 +010057#endif
Manuel Pégourié-Gonnard21718762023-11-10 11:21:17 +010058 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 */