Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 1 | /** |
| 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 |
| 21 | extern "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 | */ |
| 30 | static 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 | */ |
| 49 | int mbedtls_block_cipher_setup(mbedtls_block_cipher_context_t *ctx, |
| 50 | mbedtls_cipher_id_t cipher_id); |
| 51 | |
| 52 | /** |
Manuel Pégourié-Gonnard | 3e0884f | 2023-11-10 11:52:10 +0100 | [diff] [blame^] | 53 | * \brief Set the key into the context. |
| 54 | * |
| 55 | * \param ctx The context to configure. |
| 56 | * \param key The buffer holding the key material. |
| 57 | * \param key_bitlen The size of the key in bits. |
| 58 | * |
| 59 | * \retval \c 0 on success. |
| 60 | * \retval #MBEDTLS_ERR_CIPHER_INVALID_CONTEXT if the context was not |
| 61 | * properly set up before calling this function. |
| 62 | * \retval One of #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH, |
| 63 | * #MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 64 | * #MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA if \p key_bitlen is |
| 65 | * invalid. |
| 66 | */ |
| 67 | int mbedtls_block_cipher_setkey(mbedtls_block_cipher_context_t *ctx, |
| 68 | const unsigned char *key, |
| 69 | unsigned key_bitlen); |
| 70 | /** |
Manuel Pégourié-Gonnard | 2171876 | 2023-11-10 11:21:17 +0100 | [diff] [blame] | 71 | * \brief Clear the context. |
| 72 | * |
| 73 | * \param ctx The context to clear. |
| 74 | */ |
| 75 | void mbedtls_block_cipher_free(mbedtls_block_cipher_context_t *ctx); |
| 76 | |
| 77 | #ifdef __cplusplus |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | #endif /* MBEDTLS_BLOCK_CIPHER_INTERNAL_H */ |