blob: d76d860eaac8606e81e6317cee0e4a060fca793e [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)
28#include "psa/crypto.h"
29#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)
55 mbedtls_block_cipher_engine_t engine;
56 psa_cipher_operation_t psa_operation;
57 psa_key_type_t psa_key_type;
58 mbedtls_svc_key_id_t psa_key_id;
59#endif
Manuel Pégourié-Gonnard21718762023-11-10 11:21:17 +010060 union {
61 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
62#if defined(MBEDTLS_AES_C)
63 mbedtls_aes_context MBEDTLS_PRIVATE(aes);
64#endif
65#if defined(MBEDTLS_ARIA_C)
66 mbedtls_aria_context MBEDTLS_PRIVATE(aria);
67#endif
68#if defined(MBEDTLS_CAMELLIA_C)
69 mbedtls_camellia_context MBEDTLS_PRIVATE(camellia);
70#endif
71 } MBEDTLS_PRIVATE(ctx);
72} mbedtls_block_cipher_context_t;
73
74#ifdef __cplusplus
75}
76#endif
77
78#endif /* MBEDTLS_BLOCK_CIPHER_H */