blob: 2623a42fed6f7b06d54be30a5d281360d2add0f9 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file aes.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +01004 * \brief This file contains AES definitions and functions.
5 *
6 * The Advanced Encryption Standard (AES) specifies a FIPS-approved
Rose Zadik7f441272018-01-22 11:48:23 +00007 * cryptographic algorithm that can be used to protect electronic
8 * data.
9 *
10 * The AES algorithm is a symmetric block cipher that can
11 * encrypt and decrypt information. For more information, see
12 * <em>FIPS Publication 197: Advanced Encryption Standard</em> and
13 * <em>ISO/IEC 18033-2:2006: Information technology -- Security
14 * techniques -- Encryption algorithms -- Part 2: Asymmetric
15 * ciphers</em>.
Jaeden Amerof167deb2018-05-30 19:20:48 +010016 *
17 * The AES-XTS block mode is standardized by NIST SP 800-38E
18 * <https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38e.pdf>
19 * and described in detail by IEEE P1619
20 * <https://ieeexplore.ieee.org/servlet/opac?punumber=4375278>.
Darryl Greena40a1012018-01-05 15:33:17 +000021 */
Rose Zadik5ad7aea2018-03-26 12:00:09 +010022
Bence Szépkúti86974652020-06-15 11:59:37 +020023/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020024 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000025 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Rose Zadik7f441272018-01-22 11:48:23 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#ifndef MBEDTLS_AES_H
29#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010032#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#endif
Gilles Peskine7b8571f2021-07-07 21:02:36 +020036#include "mbedtls/platform_util.h"
Paul Bakker90995b52013-06-24 19:20:35 +020037
Rich Evans00ab4702015-02-06 13:43:58 +000038#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020039#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000040
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010041/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000042#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
43#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000044
Andres Amaya Garciac5380642017-11-28 19:57:51 +000045/* Error codes in range 0x0020-0x0022 */
Gilles Peskinea3974432021-07-26 18:48:10 +020046/** Invalid key length. */
47#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
48/** Invalid data input length. */
49#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
Paul Bakker2b222c82009-07-27 21:03:45 +000050
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000051/* Error codes in range 0x0021-0x0025 */
Gilles Peskinea3974432021-07-26 18:48:10 +020052/** Invalid input data. */
53#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
Ron Eldor9924bdc2018-10-04 10:59:13 +030054
55/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020056/** Feature not available. For example, an unsupported AES key size. */
57#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
Ron Eldor9924bdc2018-10-04 10:59:13 +030058
59/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020060/** AES hardware accelerator failed. */
61#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
Paul Bakker5121ce52009-01-03 21:22:43 +000062
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010063#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
Andres AGf5bf7182017-03-03 14:09:56 +000064 !defined(inline) && !defined(__cplusplus)
65#define inline __inline
66#endif
67
Paul Bakker407a0da2013-06-27 14:29:21 +020068#ifdef __cplusplus
69extern "C" {
70#endif
71
Ron Eldorb2aacec2017-05-18 16:53:08 +030072#if !defined(MBEDTLS_AES_ALT)
73// Regular implementation
74//
75
Paul Bakker5121ce52009-01-03 21:22:43 +000076/**
Rose Zadik7f441272018-01-22 11:48:23 +000077 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000078 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010079typedef struct mbedtls_aes_context {
Rose Zadik7f441272018-01-22 11:48:23 +000080 int nr; /*!< The number of rounds. */
81 uint32_t *rk; /*!< AES round keys. */
82 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
83 hold 32 extra Bytes, which can be used for
84 one of the following purposes:
85 <ul><li>Alignment if VIA padlock is
86 used.</li>
87 <li>Simplifying key expansion in the 256-bit
88 case by generating an extra round key.
89 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +000090}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000092
Jaeden Amero9366feb2018-05-29 18:55:17 +010093#if defined(MBEDTLS_CIPHER_MODE_XTS)
94/**
95 * \brief The AES XTS context-type definition.
96 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010097typedef struct mbedtls_aes_xts_context {
Jaeden Amero9366feb2018-05-29 18:55:17 +010098 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
99 encryption or decryption. */
100 mbedtls_aes_context tweak; /*!< The AES context used for tweak
101 computation. */
102} mbedtls_aes_xts_context;
103#endif /* MBEDTLS_CIPHER_MODE_XTS */
104
Ron Eldorb2aacec2017-05-18 16:53:08 +0300105#else /* MBEDTLS_AES_ALT */
106#include "aes_alt.h"
107#endif /* MBEDTLS_AES_ALT */
108
Paul Bakker5121ce52009-01-03 21:22:43 +0000109/**
Rose Zadik7f441272018-01-22 11:48:23 +0000110 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200111 *
Rose Zadik7f441272018-01-22 11:48:23 +0000112 * It must be the first API called before using
113 * the context.
114 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500115 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200116 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100117void mbedtls_aes_init(mbedtls_aes_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200118
119/**
Rose Zadik7f441272018-01-22 11:48:23 +0000120 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200121 *
Rose Zadik7f441272018-01-22 11:48:23 +0000122 * \param ctx The AES context to clear.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500123 * If this is \c NULL, this function does nothing.
124 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200125 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100126void mbedtls_aes_free(mbedtls_aes_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200127
Jaeden Amero9366feb2018-05-29 18:55:17 +0100128#if defined(MBEDTLS_CIPHER_MODE_XTS)
129/**
130 * \brief This function initializes the specified AES XTS context.
131 *
132 * It must be the first API called before using
133 * the context.
134 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500135 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100136 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100137void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100138
139/**
140 * \brief This function releases and clears the specified AES XTS context.
141 *
142 * \param ctx The AES XTS context to clear.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500143 * If this is \c NULL, this function does nothing.
144 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100145 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100146void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100147#endif /* MBEDTLS_CIPHER_MODE_XTS */
148
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200149/**
Rose Zadik7f441272018-01-22 11:48:23 +0000150 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 *
Rose Zadik7f441272018-01-22 11:48:23 +0000152 * \param ctx The AES context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500153 * It must be initialized.
Rose Zadik7f441272018-01-22 11:48:23 +0000154 * \param key The encryption key.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500155 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000156 * \param keybits The size of data passed in bits. Valid options are:
157 * <ul><li>128 bits</li>
158 * <li>192 bits</li>
159 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000160 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100161 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100162 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200164MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100165int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
166 unsigned int keybits);
Paul Bakker5121ce52009-01-03 21:22:43 +0000167
168/**
Rose Zadik7f441272018-01-22 11:48:23 +0000169 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000170 *
Rose Zadik7f441272018-01-22 11:48:23 +0000171 * \param ctx The AES context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500172 * It must be initialized.
Rose Zadik7f441272018-01-22 11:48:23 +0000173 * \param key The decryption key.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500174 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000175 * \param keybits The size of data passed. Valid options are:
176 * <ul><li>128 bits</li>
177 * <li>192 bits</li>
178 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000179 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100180 * \return \c 0 on success.
181 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000182 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200183MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100184int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
185 unsigned int keybits);
Paul Bakker5121ce52009-01-03 21:22:43 +0000186
Jaeden Amero9366feb2018-05-29 18:55:17 +0100187#if defined(MBEDTLS_CIPHER_MODE_XTS)
188/**
189 * \brief This function prepares an XTS context for encryption and
190 * sets the encryption key.
191 *
192 * \param ctx The AES XTS context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500193 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100194 * \param key The encryption key. This is comprised of the XTS key1
195 * concatenated with the XTS key2.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500196 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100197 * \param keybits The size of \p key passed in bits. Valid options are:
198 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
199 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
200 *
201 * \return \c 0 on success.
202 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
203 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200204MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100205int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx,
206 const unsigned char *key,
207 unsigned int keybits);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100208
209/**
210 * \brief This function prepares an XTS context for decryption and
211 * sets the decryption key.
212 *
213 * \param ctx The AES XTS context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500214 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100215 * \param key The decryption key. This is comprised of the XTS key1
216 * concatenated with the XTS key2.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500217 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100218 * \param keybits The size of \p key passed in bits. Valid options are:
219 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
220 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
221 *
222 * \return \c 0 on success.
223 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
224 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200225MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100226int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx,
227 const unsigned char *key,
228 unsigned int keybits);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100229#endif /* MBEDTLS_CIPHER_MODE_XTS */
230
Paul Bakker5121ce52009-01-03 21:22:43 +0000231/**
Rose Zadik7f441272018-01-22 11:48:23 +0000232 * \brief This function performs an AES single-block encryption or
233 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000234 *
Rose Zadik7f441272018-01-22 11:48:23 +0000235 * It performs the operation defined in the \p mode parameter
236 * (encrypt or decrypt), on the input data buffer defined in
237 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000238 *
Rose Zadik7f441272018-01-22 11:48:23 +0000239 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
240 * mbedtls_aes_setkey_dec() must be called before the first
241 * call to this API with the same context.
242 *
243 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500244 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000245 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
246 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500247 * \param input The buffer holding the input data.
248 * It must be readable and at least \c 16 Bytes long.
249 * \param output The buffer where the output data will be written.
250 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000251
252 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000253 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200254MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100255int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
256 int mode,
257 const unsigned char input[16],
258 unsigned char output[16]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000259
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000261/**
Rose Zadik7f441272018-01-22 11:48:23 +0000262 * \brief This function performs an AES-CBC encryption or decryption operation
263 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000264 *
Rose Zadik7f441272018-01-22 11:48:23 +0000265 * It performs the operation defined in the \p mode
266 * parameter (encrypt/decrypt), on the input data buffer defined in
267 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000268 *
Rose Zadik7f441272018-01-22 11:48:23 +0000269 * It can be called as many times as needed, until all the input
270 * data is processed. mbedtls_aes_init(), and either
271 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
272 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000273 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500274 * \note This function operates on full blocks, that is, the input size
275 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000276 *
277 * \note Upon exit, the content of the IV is updated so that you can
278 * call the same function again on the next
279 * block(s) of data and get the same result as if it was
280 * encrypted in one call. This allows a "streaming" usage.
281 * If you need to retain the contents of the IV, you should
282 * either save it manually or use the cipher module instead.
283 *
284 *
285 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500286 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000287 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
288 * #MBEDTLS_AES_DECRYPT.
289 * \param length The length of the input data in Bytes. This must be a
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500290 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000291 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500292 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000293 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500294 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000295 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500296 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000297 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100298 * \return \c 0 on success.
299 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000300 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000301 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200302MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100303int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
304 int mode,
305 size_t length,
306 unsigned char iv[16],
307 const unsigned char *input,
308 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000310
Aorimn5f778012016-06-09 23:22:58 +0200311#if defined(MBEDTLS_CIPHER_MODE_XTS)
312/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100313 * \brief This function performs an AES-XTS encryption or decryption
314 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200315 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100316 * AES-XTS encrypts or decrypts blocks based on their location as
317 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100318 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200319 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100320 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
321 * AES blocks. If the data unit is larger than this, this function
322 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
323 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100324 * \param ctx The AES XTS context to use for AES XTS operations.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500325 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100326 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
327 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500328 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100329 * length between 16 bytes and 2^24 bytes inclusive
330 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100331 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100332 * bytes in little-endian format. For disk encryption, this
333 * is typically the index of the block device sector that
334 * contains the data.
335 * \param input The buffer holding the input data (which is an entire
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500336 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100337 * input.
338 * \param output The buffer holding the output data (which is an entire
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500339 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100340 * output.
Aorimn5f778012016-06-09 23:22:58 +0200341 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100342 * \return \c 0 on success.
343 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500344 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100345 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200346 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200347MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100348int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx,
349 int mode,
350 size_t length,
351 const unsigned char data_unit[16],
352 const unsigned char *input,
353 unsigned char *output);
Aorimn5f778012016-06-09 23:22:58 +0200354#endif /* MBEDTLS_CIPHER_MODE_XTS */
355
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200356#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000357/**
Rose Zadik7f441272018-01-22 11:48:23 +0000358 * \brief This function performs an AES-CFB128 encryption or decryption
359 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000360 *
Rose Zadik7f441272018-01-22 11:48:23 +0000361 * It performs the operation defined in the \p mode
362 * parameter (encrypt or decrypt), on the input data buffer
363 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000364 *
Rose Zadik7f441272018-01-22 11:48:23 +0000365 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
366 * regardless of whether you are performing an encryption or decryption
367 * operation, that is, regardless of the \p mode parameter. This is
368 * because CFB mode uses the same key schedule for encryption and
369 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000370 *
Rose Zadik7f441272018-01-22 11:48:23 +0000371 * \note Upon exit, the content of the IV is updated so that you can
372 * call the same function again on the next
373 * block(s) of data and get the same result as if it was
374 * encrypted in one call. This allows a "streaming" usage.
375 * If you need to retain the contents of the
376 * IV, you must either save it manually or use the cipher
377 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000378 *
Rose Zadik7f441272018-01-22 11:48:23 +0000379 *
380 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500381 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000382 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
383 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500384 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000385 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500386 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000387 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500388 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000389 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500390 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000391 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500392 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000393 *
394 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000395 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200396MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100397int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx,
398 int mode,
399 size_t length,
400 size_t *iv_off,
401 unsigned char iv[16],
402 const unsigned char *input,
403 unsigned char *output);
Paul Bakker5121ce52009-01-03 21:22:43 +0000404
Paul Bakker9a736322012-11-14 12:39:52 +0000405/**
Rose Zadik7f441272018-01-22 11:48:23 +0000406 * \brief This function performs an AES-CFB8 encryption or decryption
407 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100408 *
Rose Zadik7f441272018-01-22 11:48:23 +0000409 * It performs the operation defined in the \p mode
410 * parameter (encrypt/decrypt), on the input data buffer defined
411 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100412 *
Rose Zadik7f441272018-01-22 11:48:23 +0000413 * Due to the nature of CFB, you must use the same key schedule for
414 * both encryption and decryption operations. Therefore, you must
415 * use the context initialized with mbedtls_aes_setkey_enc() for
416 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000417 *
Rose Zadik7f441272018-01-22 11:48:23 +0000418 * \note Upon exit, the content of the IV is updated so that you can
419 * call the same function again on the next
420 * block(s) of data and get the same result as if it was
421 * encrypted in one call. This allows a "streaming" usage.
422 * If you need to retain the contents of the
423 * IV, you should either save it manually or use the cipher
424 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100425 *
Rose Zadik7f441272018-01-22 11:48:23 +0000426 *
427 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500428 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000429 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
430 * #MBEDTLS_AES_DECRYPT
431 * \param length The length of the input data.
432 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500433 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000434 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500435 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000436 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500437 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000438 *
439 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100440 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200441MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100442int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx,
443 int mode,
444 size_t length,
445 unsigned char iv[16],
446 const unsigned char *input,
447 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200448#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100449
Simon Butcher76a5b222018-04-22 22:57:27 +0100450#if defined(MBEDTLS_CIPHER_MODE_OFB)
451/**
Simon Butcher5db13622018-06-04 22:11:25 +0100452 * \brief This function performs an AES-OFB (Output Feedback Mode)
453 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100454 *
Simon Butcher5db13622018-06-04 22:11:25 +0100455 * For OFB, you must set up the context with
456 * mbedtls_aes_setkey_enc(), regardless of whether you are
457 * performing an encryption or decryption operation. This is
458 * because OFB mode uses the same key schedule for encryption and
459 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100460 *
Simon Butcher5db13622018-06-04 22:11:25 +0100461 * The OFB operation is identical for encryption or decryption,
462 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100463 *
Simon Butcher5db13622018-06-04 22:11:25 +0100464 * \note Upon exit, the content of iv, the Initialisation Vector, is
465 * updated so that you can call the same function again on the next
466 * block(s) of data and get the same result as if it was encrypted
467 * in one call. This allows a "streaming" usage, by initialising
468 * iv_off to 0 before the first call, and preserving its value
469 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100470 *
Simon Butcher5db13622018-06-04 22:11:25 +0100471 * For non-streaming use, the iv should be initialised on each call
472 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100473 *
Simon Butcher5db13622018-06-04 22:11:25 +0100474 * If you need to retain the contents of the initialisation vector,
475 * you must either save it manually or use the cipher module
476 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100477 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100478 * \warning For the OFB mode, the initialisation vector must be unique
479 * every encryption operation. Reuse of an initialisation vector
480 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100481 *
482 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500483 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100484 * \param length The length of the input data.
485 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500486 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100487 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500488 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100489 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500490 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100491 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500492 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100493 *
494 * \return \c 0 on success.
495 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200496MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100497int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx,
498 size_t length,
499 size_t *iv_off,
500 unsigned char iv[16],
501 const unsigned char *input,
502 unsigned char *output);
Simon Butcher76a5b222018-04-22 22:57:27 +0100503
504#endif /* MBEDTLS_CIPHER_MODE_OFB */
505
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200506#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100507/**
Rose Zadik7f441272018-01-22 11:48:23 +0000508 * \brief This function performs an AES-CTR encryption or decryption
509 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000510 *
Rose Zadik7f441272018-01-22 11:48:23 +0000511 * Due to the nature of CTR, you must use the same key schedule
512 * for both encryption and decryption operations. Therefore, you
513 * must use the context initialized with mbedtls_aes_setkey_enc()
514 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000515 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100516 * \warning You must never reuse a nonce value with the same key. Doing so
517 * would void the encryption for the two messages encrypted with
518 * the same nonce and key.
519 *
520 * There are two common strategies for managing nonces with CTR:
521 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200522 * 1. You can handle everything as a single message processed over
523 * successive calls to this function. In that case, you want to
524 * set \p nonce_counter and \p nc_off to 0 for the first call, and
525 * then preserve the values of \p nonce_counter, \p nc_off and \p
526 * stream_block across calls to this function as they will be
527 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100528 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200529 * With this strategy, you must not encrypt more than 2**128
530 * blocks of data with the same key.
531 *
532 * 2. You can encrypt separate messages by dividing the \p
533 * nonce_counter buffer in two areas: the first one used for a
534 * per-message nonce, handled by yourself, and the second one
535 * updated by this function internally.
536 *
537 * For example, you might reserve the first 12 bytes for the
538 * per-message nonce, and the last 4 bytes for internal use. In that
539 * case, before calling this function on a new message you need to
540 * set the first 12 bytes of \p nonce_counter to your chosen nonce
541 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
542 * stream_block to be ignored). That way, you can encrypt at most
543 * 2**96 messages of up to 2**32 blocks each with the same key.
544 *
545 * The per-message nonce (or information sufficient to reconstruct
546 * it) needs to be communicated with the ciphertext and must be unique.
547 * The recommended way to ensure uniqueness is to use a message
548 * counter. An alternative is to generate random nonces, but this
549 * limits the number of messages that can be securely encrypted:
550 * for example, with 96-bit random nonces, you should not encrypt
551 * more than 2**32 messages with the same key.
552 *
Tom Cosgrove2b150752022-05-26 11:55:43 +0100553 * Note that for both strategies, sizes are measured in blocks and
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200554 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000555 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200556 * \warning Upon return, \p stream_block contains sensitive data. Its
557 * content must not be written to insecure storage and should be
558 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000559 *
Rose Zadik7f441272018-01-22 11:48:23 +0000560 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500561 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000562 * \param length The length of the input data.
563 * \param nc_off The offset in the current \p stream_block, for
564 * resuming within the current cipher stream. The
565 * offset pointer should be 0 at the start of a stream.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500566 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000567 * \param nonce_counter The 128-bit nonce and counter.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500568 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000569 * \param stream_block The saved stream block for resuming. This is
570 * overwritten by the function.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500571 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000572 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500573 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000574 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500575 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000576 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100577 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000578 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200579MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100580int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx,
581 size_t length,
582 size_t *nc_off,
583 unsigned char nonce_counter[16],
584 unsigned char stream_block[16],
585 const unsigned char *input,
586 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200587#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200588
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200589/**
Rose Zadik7f441272018-01-22 11:48:23 +0000590 * \brief Internal AES block encryption function. This is only
591 * exposed to allow overriding it using
592 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200593 *
Rose Zadik7f441272018-01-22 11:48:23 +0000594 * \param ctx The AES context to use for encryption.
595 * \param input The plaintext block.
596 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000597 *
Rose Zadik7f441272018-01-22 11:48:23 +0000598 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200599 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200600MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100601int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
602 const unsigned char input[16],
603 unsigned char output[16]);
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200604
605/**
Rose Zadik7f441272018-01-22 11:48:23 +0000606 * \brief Internal AES block decryption function. This is only
607 * exposed to allow overriding it using see
608 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200609 *
Rose Zadik7f441272018-01-22 11:48:23 +0000610 * \param ctx The AES context to use for decryption.
611 * \param input The ciphertext block.
612 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000613 *
Rose Zadik7f441272018-01-22 11:48:23 +0000614 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200615 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200616MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100617int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
618 const unsigned char input[16],
619 unsigned char output[16]);
Andres AGf5bf7182017-03-03 14:09:56 +0000620
621#if !defined(MBEDTLS_DEPRECATED_REMOVED)
622#if defined(MBEDTLS_DEPRECATED_WARNING)
623#define MBEDTLS_DEPRECATED __attribute__((deprecated))
624#else
625#define MBEDTLS_DEPRECATED
626#endif
627/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100628 * \brief Deprecated internal AES block encryption function
629 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000630 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500631 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000632 *
Rose Zadik7f441272018-01-22 11:48:23 +0000633 * \param ctx The AES context to use for encryption.
634 * \param input Plaintext block.
635 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000636 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100637MBEDTLS_DEPRECATED void mbedtls_aes_encrypt(mbedtls_aes_context *ctx,
638 const unsigned char input[16],
639 unsigned char output[16]);
Andres AGf5bf7182017-03-03 14:09:56 +0000640
641/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100642 * \brief Deprecated internal AES block decryption function
643 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000644 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500645 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000646 *
Rose Zadik7f441272018-01-22 11:48:23 +0000647 * \param ctx The AES context to use for decryption.
648 * \param input Ciphertext block.
649 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000650 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100651MBEDTLS_DEPRECATED void mbedtls_aes_decrypt(mbedtls_aes_context *ctx,
652 const unsigned char input[16],
653 unsigned char output[16]);
Andres AGf5bf7182017-03-03 14:09:56 +0000654
655#undef MBEDTLS_DEPRECATED
656#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200657
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500658
659#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000660/**
Rose Zadik7f441272018-01-22 11:48:23 +0000661 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000662 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100663 * \return \c 0 on success.
664 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000665 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200666MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100667int mbedtls_aes_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000668
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500669#endif /* MBEDTLS_SELF_TEST */
670
Paul Bakker5121ce52009-01-03 21:22:43 +0000671#ifdef __cplusplus
672}
673#endif
674
675#endif /* aes.h */