blob: fb2322a6bb9bfd79169716af092cb24b47380e9e [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
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020025 * SPDX-License-Identifier: Apache-2.0
26 *
27 * Licensed under the Apache License, Version 2.0 (the "License"); you may
28 * not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 * http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
Paul Bakker5121ce52009-01-03 21:22:43 +000038 */
Rose Zadik7f441272018-01-22 11:48:23 +000039
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#ifndef MBEDTLS_AES_H
41#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000042
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010044#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020045#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020046#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020047#endif
Gilles Peskine7b8571f2021-07-07 21:02:36 +020048#include "mbedtls/platform_util.h"
Paul Bakker90995b52013-06-24 19:20:35 +020049
Rich Evans00ab4702015-02-06 13:43:58 +000050#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020051#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000052
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010053/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000054#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
55#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Andres Amaya Garciac5380642017-11-28 19:57:51 +000057/* Error codes in range 0x0020-0x0022 */
Gilles Peskinea3974432021-07-26 18:48:10 +020058/** Invalid key length. */
59#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
60/** Invalid data input length. */
61#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
Paul Bakker2b222c82009-07-27 21:03:45 +000062
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000063/* Error codes in range 0x0021-0x0025 */
Gilles Peskinea3974432021-07-26 18:48:10 +020064/** Invalid input data. */
65#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
Ron Eldor9924bdc2018-10-04 10:59:13 +030066
67/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020068/** Feature not available. For example, an unsupported AES key size. */
69#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
Ron Eldor9924bdc2018-10-04 10:59:13 +030070
71/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskinea3974432021-07-26 18:48:10 +020072/** AES hardware accelerator failed. */
73#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
Paul Bakker5121ce52009-01-03 21:22:43 +000074
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010075#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
Andres AGf5bf7182017-03-03 14:09:56 +000076 !defined(inline) && !defined(__cplusplus)
77#define inline __inline
78#endif
79
Paul Bakker407a0da2013-06-27 14:29:21 +020080#ifdef __cplusplus
81extern "C" {
82#endif
83
Ron Eldorb2aacec2017-05-18 16:53:08 +030084#if !defined(MBEDTLS_AES_ALT)
85// Regular implementation
86//
87
Paul Bakker5121ce52009-01-03 21:22:43 +000088/**
Rose Zadik7f441272018-01-22 11:48:23 +000089 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000090 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010091typedef struct mbedtls_aes_context {
Rose Zadik7f441272018-01-22 11:48:23 +000092 int nr; /*!< The number of rounds. */
93 uint32_t *rk; /*!< AES round keys. */
94 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
95 hold 32 extra Bytes, which can be used for
96 one of the following purposes:
97 <ul><li>Alignment if VIA padlock is
98 used.</li>
99 <li>Simplifying key expansion in the 256-bit
100 case by generating an extra round key.
101 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +0000102}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
Jaeden Amero9366feb2018-05-29 18:55:17 +0100105#if defined(MBEDTLS_CIPHER_MODE_XTS)
106/**
107 * \brief The AES XTS context-type definition.
108 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100109typedef struct mbedtls_aes_xts_context {
Jaeden Amero9366feb2018-05-29 18:55:17 +0100110 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
111 encryption or decryption. */
112 mbedtls_aes_context tweak; /*!< The AES context used for tweak
113 computation. */
114} mbedtls_aes_xts_context;
115#endif /* MBEDTLS_CIPHER_MODE_XTS */
116
Ron Eldorb2aacec2017-05-18 16:53:08 +0300117#else /* MBEDTLS_AES_ALT */
118#include "aes_alt.h"
119#endif /* MBEDTLS_AES_ALT */
120
Paul Bakker5121ce52009-01-03 21:22:43 +0000121/**
Rose Zadik7f441272018-01-22 11:48:23 +0000122 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200123 *
Rose Zadik7f441272018-01-22 11:48:23 +0000124 * It must be the first API called before using
125 * the context.
126 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500127 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200128 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100129void mbedtls_aes_init(mbedtls_aes_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200130
131/**
Rose Zadik7f441272018-01-22 11:48:23 +0000132 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200133 *
Rose Zadik7f441272018-01-22 11:48:23 +0000134 * \param ctx The AES context to clear.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500135 * If this is \c NULL, this function does nothing.
136 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200137 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100138void mbedtls_aes_free(mbedtls_aes_context *ctx);
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200139
Jaeden Amero9366feb2018-05-29 18:55:17 +0100140#if defined(MBEDTLS_CIPHER_MODE_XTS)
141/**
142 * \brief This function initializes the specified AES XTS context.
143 *
144 * It must be the first API called before using
145 * the context.
146 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500147 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100148 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100149void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100150
151/**
152 * \brief This function releases and clears the specified AES XTS context.
153 *
154 * \param ctx The AES XTS context to clear.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500155 * If this is \c NULL, this function does nothing.
156 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100157 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100158void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100159#endif /* MBEDTLS_CIPHER_MODE_XTS */
160
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200161/**
Rose Zadik7f441272018-01-22 11:48:23 +0000162 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 *
Rose Zadik7f441272018-01-22 11:48:23 +0000164 * \param ctx The AES context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500165 * It must be initialized.
Rose Zadik7f441272018-01-22 11:48:23 +0000166 * \param key The encryption key.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500167 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000168 * \param keybits The size of data passed in bits. Valid options are:
169 * <ul><li>128 bits</li>
170 * <li>192 bits</li>
171 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000172 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100173 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100174 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000175 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200176MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100177int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
178 unsigned int keybits);
Paul Bakker5121ce52009-01-03 21:22:43 +0000179
180/**
Rose Zadik7f441272018-01-22 11:48:23 +0000181 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000182 *
Rose Zadik7f441272018-01-22 11:48:23 +0000183 * \param ctx The AES context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500184 * It must be initialized.
Rose Zadik7f441272018-01-22 11:48:23 +0000185 * \param key The decryption key.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500186 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000187 * \param keybits The size of data passed. Valid options are:
188 * <ul><li>128 bits</li>
189 * <li>192 bits</li>
190 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000191 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100192 * \return \c 0 on success.
193 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000194 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200195MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100196int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
197 unsigned int keybits);
Paul Bakker5121ce52009-01-03 21:22:43 +0000198
Jaeden Amero9366feb2018-05-29 18:55:17 +0100199#if defined(MBEDTLS_CIPHER_MODE_XTS)
200/**
201 * \brief This function prepares an XTS context for encryption and
202 * sets the encryption key.
203 *
204 * \param ctx The AES XTS context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500205 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100206 * \param key The encryption key. This is comprised of the XTS key1
207 * concatenated with the XTS key2.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500208 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100209 * \param keybits The size of \p key passed in bits. Valid options are:
210 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
211 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
212 *
213 * \return \c 0 on success.
214 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
215 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200216MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100217int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx,
218 const unsigned char *key,
219 unsigned int keybits);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100220
221/**
222 * \brief This function prepares an XTS context for decryption and
223 * sets the decryption key.
224 *
225 * \param ctx The AES XTS context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500226 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100227 * \param key The decryption key. This is comprised of the XTS key1
228 * concatenated with the XTS key2.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500229 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100230 * \param keybits The size of \p key passed in bits. Valid options are:
231 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
232 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
233 *
234 * \return \c 0 on success.
235 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
236 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200237MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100238int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx,
239 const unsigned char *key,
240 unsigned int keybits);
Jaeden Amero9366feb2018-05-29 18:55:17 +0100241#endif /* MBEDTLS_CIPHER_MODE_XTS */
242
Paul Bakker5121ce52009-01-03 21:22:43 +0000243/**
Rose Zadik7f441272018-01-22 11:48:23 +0000244 * \brief This function performs an AES single-block encryption or
245 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000246 *
Rose Zadik7f441272018-01-22 11:48:23 +0000247 * It performs the operation defined in the \p mode parameter
248 * (encrypt or decrypt), on the input data buffer defined in
249 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000250 *
Rose Zadik7f441272018-01-22 11:48:23 +0000251 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
252 * mbedtls_aes_setkey_dec() must be called before the first
253 * call to this API with the same context.
254 *
255 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500256 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000257 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
258 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500259 * \param input The buffer holding the input data.
260 * It must be readable and at least \c 16 Bytes long.
261 * \param output The buffer where the output data will be written.
262 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000263
264 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000265 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200266MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100267int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
268 int mode,
269 const unsigned char input[16],
270 unsigned char output[16]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000271
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000273/**
Rose Zadik7f441272018-01-22 11:48:23 +0000274 * \brief This function performs an AES-CBC encryption or decryption operation
275 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000276 *
Rose Zadik7f441272018-01-22 11:48:23 +0000277 * It performs the operation defined in the \p mode
278 * parameter (encrypt/decrypt), on the input data buffer defined in
279 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000280 *
Rose Zadik7f441272018-01-22 11:48:23 +0000281 * It can be called as many times as needed, until all the input
282 * data is processed. mbedtls_aes_init(), and either
283 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
284 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000285 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500286 * \note This function operates on full blocks, that is, the input size
287 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000288 *
289 * \note Upon exit, the content of the IV is updated so that you can
290 * call the same function again on the next
291 * block(s) of data and get the same result as if it was
292 * encrypted in one call. This allows a "streaming" usage.
293 * If you need to retain the contents of the IV, you should
294 * either save it manually or use the cipher module instead.
295 *
296 *
297 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500298 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000299 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
300 * #MBEDTLS_AES_DECRYPT.
301 * \param length The length of the input data in Bytes. This must be a
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500302 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000303 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500304 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000305 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500306 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000307 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500308 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000309 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100310 * \return \c 0 on success.
311 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000312 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000313 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200314MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100315int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
316 int mode,
317 size_t length,
318 unsigned char iv[16],
319 const unsigned char *input,
320 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000322
Aorimn5f778012016-06-09 23:22:58 +0200323#if defined(MBEDTLS_CIPHER_MODE_XTS)
324/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100325 * \brief This function performs an AES-XTS encryption or decryption
326 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200327 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100328 * AES-XTS encrypts or decrypts blocks based on their location as
329 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100330 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200331 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100332 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
333 * AES blocks. If the data unit is larger than this, this function
334 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
335 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100336 * \param ctx The AES XTS context to use for AES XTS operations.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500337 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100338 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
339 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500340 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100341 * length between 16 bytes and 2^24 bytes inclusive
342 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100343 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100344 * bytes in little-endian format. For disk encryption, this
345 * is typically the index of the block device sector that
346 * contains the data.
347 * \param input The buffer holding the input data (which is an entire
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500348 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100349 * input.
350 * \param output The buffer holding the output data (which is an entire
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500351 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100352 * output.
Aorimn5f778012016-06-09 23:22:58 +0200353 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100354 * \return \c 0 on success.
355 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500356 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100357 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200358 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200359MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100360int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx,
361 int mode,
362 size_t length,
363 const unsigned char data_unit[16],
364 const unsigned char *input,
365 unsigned char *output);
Aorimn5f778012016-06-09 23:22:58 +0200366#endif /* MBEDTLS_CIPHER_MODE_XTS */
367
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000369/**
Rose Zadik7f441272018-01-22 11:48:23 +0000370 * \brief This function performs an AES-CFB128 encryption or decryption
371 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000372 *
Rose Zadik7f441272018-01-22 11:48:23 +0000373 * It performs the operation defined in the \p mode
374 * parameter (encrypt or decrypt), on the input data buffer
375 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000376 *
Rose Zadik7f441272018-01-22 11:48:23 +0000377 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
378 * regardless of whether you are performing an encryption or decryption
379 * operation, that is, regardless of the \p mode parameter. This is
380 * because CFB mode uses the same key schedule for encryption and
381 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000382 *
Rose Zadik7f441272018-01-22 11:48:23 +0000383 * \note Upon exit, the content of the IV is updated so that you can
384 * call the same function again on the next
385 * block(s) of data and get the same result as if it was
386 * encrypted in one call. This allows a "streaming" usage.
387 * If you need to retain the contents of the
388 * IV, you must either save it manually or use the cipher
389 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000390 *
Rose Zadik7f441272018-01-22 11:48:23 +0000391 *
392 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500393 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000394 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
395 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500396 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000397 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500398 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000399 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500400 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000401 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500402 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000403 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500404 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000405 *
406 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000407 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200408MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100409int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx,
410 int mode,
411 size_t length,
412 size_t *iv_off,
413 unsigned char iv[16],
414 const unsigned char *input,
415 unsigned char *output);
Paul Bakker5121ce52009-01-03 21:22:43 +0000416
Paul Bakker9a736322012-11-14 12:39:52 +0000417/**
Rose Zadik7f441272018-01-22 11:48:23 +0000418 * \brief This function performs an AES-CFB8 encryption or decryption
419 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100420 *
Rose Zadik7f441272018-01-22 11:48:23 +0000421 * It performs the operation defined in the \p mode
422 * parameter (encrypt/decrypt), on the input data buffer defined
423 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100424 *
Rose Zadik7f441272018-01-22 11:48:23 +0000425 * Due to the nature of CFB, you must use the same key schedule for
426 * both encryption and decryption operations. Therefore, you must
427 * use the context initialized with mbedtls_aes_setkey_enc() for
428 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000429 *
Rose Zadik7f441272018-01-22 11:48:23 +0000430 * \note Upon exit, the content of the IV is updated so that you can
431 * call the same function again on the next
432 * block(s) of data and get the same result as if it was
433 * encrypted in one call. This allows a "streaming" usage.
434 * If you need to retain the contents of the
435 * IV, you should either save it manually or use the cipher
436 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100437 *
Rose Zadik7f441272018-01-22 11:48:23 +0000438 *
439 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500440 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000441 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
442 * #MBEDTLS_AES_DECRYPT
443 * \param length The length of the input data.
444 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500445 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000446 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500447 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000448 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500449 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000450 *
451 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100452 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200453MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100454int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx,
455 int mode,
456 size_t length,
457 unsigned char iv[16],
458 const unsigned char *input,
459 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200460#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100461
Simon Butcher76a5b222018-04-22 22:57:27 +0100462#if defined(MBEDTLS_CIPHER_MODE_OFB)
463/**
Simon Butcher5db13622018-06-04 22:11:25 +0100464 * \brief This function performs an AES-OFB (Output Feedback Mode)
465 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100466 *
Simon Butcher5db13622018-06-04 22:11:25 +0100467 * For OFB, you must set up the context with
468 * mbedtls_aes_setkey_enc(), regardless of whether you are
469 * performing an encryption or decryption operation. This is
470 * because OFB mode uses the same key schedule for encryption and
471 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100472 *
Simon Butcher5db13622018-06-04 22:11:25 +0100473 * The OFB operation is identical for encryption or decryption,
474 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100475 *
Simon Butcher5db13622018-06-04 22:11:25 +0100476 * \note Upon exit, the content of iv, the Initialisation Vector, is
477 * updated so that you can call the same function again on the next
478 * block(s) of data and get the same result as if it was encrypted
479 * in one call. This allows a "streaming" usage, by initialising
480 * iv_off to 0 before the first call, and preserving its value
481 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100482 *
Simon Butcher5db13622018-06-04 22:11:25 +0100483 * For non-streaming use, the iv should be initialised on each call
484 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100485 *
Simon Butcher5db13622018-06-04 22:11:25 +0100486 * If you need to retain the contents of the initialisation vector,
487 * you must either save it manually or use the cipher module
488 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100489 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100490 * \warning For the OFB mode, the initialisation vector must be unique
491 * every encryption operation. Reuse of an initialisation vector
492 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100493 *
494 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500495 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100496 * \param length The length of the input data.
497 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500498 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100499 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500500 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100501 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500502 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100503 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500504 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100505 *
506 * \return \c 0 on success.
507 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200508MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100509int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx,
510 size_t length,
511 size_t *iv_off,
512 unsigned char iv[16],
513 const unsigned char *input,
514 unsigned char *output);
Simon Butcher76a5b222018-04-22 22:57:27 +0100515
516#endif /* MBEDTLS_CIPHER_MODE_OFB */
517
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200518#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100519/**
Rose Zadik7f441272018-01-22 11:48:23 +0000520 * \brief This function performs an AES-CTR encryption or decryption
521 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000522 *
Rose Zadik7f441272018-01-22 11:48:23 +0000523 * Due to the nature of CTR, you must use the same key schedule
524 * for both encryption and decryption operations. Therefore, you
525 * must use the context initialized with mbedtls_aes_setkey_enc()
526 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000527 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100528 * \warning You must never reuse a nonce value with the same key. Doing so
529 * would void the encryption for the two messages encrypted with
530 * the same nonce and key.
531 *
532 * There are two common strategies for managing nonces with CTR:
533 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200534 * 1. You can handle everything as a single message processed over
535 * successive calls to this function. In that case, you want to
536 * set \p nonce_counter and \p nc_off to 0 for the first call, and
537 * then preserve the values of \p nonce_counter, \p nc_off and \p
538 * stream_block across calls to this function as they will be
539 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100540 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200541 * With this strategy, you must not encrypt more than 2**128
542 * blocks of data with the same key.
543 *
544 * 2. You can encrypt separate messages by dividing the \p
545 * nonce_counter buffer in two areas: the first one used for a
546 * per-message nonce, handled by yourself, and the second one
547 * updated by this function internally.
548 *
549 * For example, you might reserve the first 12 bytes for the
550 * per-message nonce, and the last 4 bytes for internal use. In that
551 * case, before calling this function on a new message you need to
552 * set the first 12 bytes of \p nonce_counter to your chosen nonce
553 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
554 * stream_block to be ignored). That way, you can encrypt at most
555 * 2**96 messages of up to 2**32 blocks each with the same key.
556 *
557 * The per-message nonce (or information sufficient to reconstruct
558 * it) needs to be communicated with the ciphertext and must be unique.
559 * The recommended way to ensure uniqueness is to use a message
560 * counter. An alternative is to generate random nonces, but this
561 * limits the number of messages that can be securely encrypted:
562 * for example, with 96-bit random nonces, you should not encrypt
563 * more than 2**32 messages with the same key.
564 *
Tom Cosgrove2b150752022-05-26 11:55:43 +0100565 * Note that for both strategies, sizes are measured in blocks and
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200566 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000567 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200568 * \warning Upon return, \p stream_block contains sensitive data. Its
569 * content must not be written to insecure storage and should be
570 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000571 *
Rose Zadik7f441272018-01-22 11:48:23 +0000572 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500573 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000574 * \param length The length of the input data.
575 * \param nc_off The offset in the current \p stream_block, for
576 * resuming within the current cipher stream. The
577 * offset pointer should be 0 at the start of a stream.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500578 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000579 * \param nonce_counter The 128-bit nonce and counter.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500580 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000581 * \param stream_block The saved stream block for resuming. This is
582 * overwritten by the function.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500583 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000584 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500585 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000586 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500587 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000588 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100589 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000590 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200591MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100592int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx,
593 size_t length,
594 size_t *nc_off,
595 unsigned char nonce_counter[16],
596 unsigned char stream_block[16],
597 const unsigned char *input,
598 unsigned char *output);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200599#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200600
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200601/**
Rose Zadik7f441272018-01-22 11:48:23 +0000602 * \brief Internal AES block encryption function. This is only
603 * exposed to allow overriding it using
604 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200605 *
Rose Zadik7f441272018-01-22 11:48:23 +0000606 * \param ctx The AES context to use for encryption.
607 * \param input The plaintext block.
608 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000609 *
Rose Zadik7f441272018-01-22 11:48:23 +0000610 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200611 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200612MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100613int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
614 const unsigned char input[16],
615 unsigned char output[16]);
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200616
617/**
Rose Zadik7f441272018-01-22 11:48:23 +0000618 * \brief Internal AES block decryption function. This is only
619 * exposed to allow overriding it using see
620 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200621 *
Rose Zadik7f441272018-01-22 11:48:23 +0000622 * \param ctx The AES context to use for decryption.
623 * \param input The ciphertext block.
624 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000625 *
Rose Zadik7f441272018-01-22 11:48:23 +0000626 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200627 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200628MBEDTLS_CHECK_RETURN_TYPICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100629int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
630 const unsigned char input[16],
631 unsigned char output[16]);
Andres AGf5bf7182017-03-03 14:09:56 +0000632
633#if !defined(MBEDTLS_DEPRECATED_REMOVED)
634#if defined(MBEDTLS_DEPRECATED_WARNING)
635#define MBEDTLS_DEPRECATED __attribute__((deprecated))
636#else
637#define MBEDTLS_DEPRECATED
638#endif
639/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100640 * \brief Deprecated internal AES block encryption function
641 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000642 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500643 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000644 *
Rose Zadik7f441272018-01-22 11:48:23 +0000645 * \param ctx The AES context to use for encryption.
646 * \param input Plaintext block.
647 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000648 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100649MBEDTLS_DEPRECATED void mbedtls_aes_encrypt(mbedtls_aes_context *ctx,
650 const unsigned char input[16],
651 unsigned char output[16]);
Andres AGf5bf7182017-03-03 14:09:56 +0000652
653/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100654 * \brief Deprecated internal AES block decryption function
655 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000656 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500657 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000658 *
Rose Zadik7f441272018-01-22 11:48:23 +0000659 * \param ctx The AES context to use for decryption.
660 * \param input Ciphertext block.
661 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000662 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100663MBEDTLS_DEPRECATED void mbedtls_aes_decrypt(mbedtls_aes_context *ctx,
664 const unsigned char input[16],
665 unsigned char output[16]);
Andres AGf5bf7182017-03-03 14:09:56 +0000666
667#undef MBEDTLS_DEPRECATED
668#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200669
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500670
671#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000672/**
Rose Zadik7f441272018-01-22 11:48:23 +0000673 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000674 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100675 * \return \c 0 on success.
676 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000677 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200678MBEDTLS_CHECK_RETURN_CRITICAL
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100679int mbedtls_aes_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000680
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500681#endif /* MBEDTLS_SELF_TEST */
682
Paul Bakker5121ce52009-01-03 21:22:43 +0000683#ifdef __cplusplus
684}
685#endif
686
687#endif /* aes.h */