blob: 4f25e26ca85d6254c79e262c3a1aef0063804339 [file] [log] [blame]
Manuel Pégourié-Gonnard21718762023-11-10 11:21:17 +01001/**
2 * \file block_cipher_internal.h
3 *
4 * \brief Lightweight abstraction layer for block ciphers with 128 bit blocks,
5 * for use by the GCM and CCM modules.
6 */
7/*
8 * Copyright The Mbed TLS Contributors
9 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
10 */
11#ifndef MBEDTLS_BLOCK_CIPHER_INTERNAL_H
12#define MBEDTLS_BLOCK_CIPHER_INTERNAL_H
13
14#include "mbedtls/build_info.h"
15
16#include "mbedtls/cipher.h"
17
18#include "mbedtls/block_cipher.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/**
25 * \brief Initialize the context.
26 * This must be the first API call before using the context.
27 *
28 * \param ctx The context to initialize.
29 */
30static inline void mbedtls_block_cipher_init(mbedtls_block_cipher_context_t *ctx)
31{
32 memset(ctx, 0, sizeof(*ctx));
33}
34
35/**
36 * \brief Set the block cipher to use with this context.
37 * This must be called after mbedtls_block_cipher_init().
38 *
39 * \param ctx The context to set up.
40 * \param cipher_id The identifier of the cipher to use.
41 * This must be either AES, ARIA or Camellia.
42 * Warning: this is a ::mbedtls_cipher_id_t,
43 * not a ::mbedtls_block_cipher_id_t!
44 *
45 * \retval \c 0 on success.
46 * \retval #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if \p cipher_id was
47 * invalid.
48 */
49int mbedtls_block_cipher_setup(mbedtls_block_cipher_context_t *ctx,
50 mbedtls_cipher_id_t cipher_id);
51
52/**
53 * \brief Clear the context.
54 *
55 * \param ctx The context to clear.
56 */
57void mbedtls_block_cipher_free(mbedtls_block_cipher_context_t *ctx);
58
59#ifdef __cplusplus
60}
61#endif
62
63#endif /* MBEDTLS_BLOCK_CIPHER_INTERNAL_H */