blob: 94ee58a83c95feac21e7bce081bce961f51c4d71 [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
Andres AGf5bf7182017-03-03 14:09:56 +000075#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
76 !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 */
Dawid Drozd428cc522018-07-24 10:02:47 +020091typedef struct mbedtls_aes_context
Paul Bakker5121ce52009-01-03 21:22:43 +000092{
Rose Zadik7f441272018-01-22 11:48:23 +000093 int nr; /*!< The number of rounds. */
94 uint32_t *rk; /*!< AES round keys. */
95 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
96 hold 32 extra Bytes, which can be used for
97 one of the following purposes:
98 <ul><li>Alignment if VIA padlock is
99 used.</li>
100 <li>Simplifying key expansion in the 256-bit
101 case by generating an extra round key.
102 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +0000103}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000105
Jaeden Amero9366feb2018-05-29 18:55:17 +0100106#if defined(MBEDTLS_CIPHER_MODE_XTS)
107/**
108 * \brief The AES XTS context-type definition.
109 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200110typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100111{
112 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
113 encryption or decryption. */
114 mbedtls_aes_context tweak; /*!< The AES context used for tweak
115 computation. */
116} mbedtls_aes_xts_context;
117#endif /* MBEDTLS_CIPHER_MODE_XTS */
118
Ron Eldorb2aacec2017-05-18 16:53:08 +0300119#else /* MBEDTLS_AES_ALT */
120#include "aes_alt.h"
121#endif /* MBEDTLS_AES_ALT */
122
Paul Bakker5121ce52009-01-03 21:22:43 +0000123/**
Rose Zadik7f441272018-01-22 11:48:23 +0000124 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200125 *
Rose Zadik7f441272018-01-22 11:48:23 +0000126 * It must be the first API called before using
127 * the context.
128 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500129 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200130 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200132
133/**
Rose Zadik7f441272018-01-22 11:48:23 +0000134 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200135 *
Rose Zadik7f441272018-01-22 11:48:23 +0000136 * \param ctx The AES context to clear.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500137 * If this is \c NULL, this function does nothing.
138 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200141
Jaeden Amero9366feb2018-05-29 18:55:17 +0100142#if defined(MBEDTLS_CIPHER_MODE_XTS)
143/**
144 * \brief This function initializes the specified AES XTS context.
145 *
146 * It must be the first API called before using
147 * the context.
148 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500149 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100150 */
151void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
152
153/**
154 * \brief This function releases and clears the specified AES XTS context.
155 *
156 * \param ctx The AES XTS context to clear.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500157 * If this is \c NULL, this function does nothing.
158 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100159 */
160void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
161#endif /* MBEDTLS_CIPHER_MODE_XTS */
162
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200163/**
Rose Zadik7f441272018-01-22 11:48:23 +0000164 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000165 *
Rose Zadik7f441272018-01-22 11:48:23 +0000166 * \param ctx The AES context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500167 * It must be initialized.
Rose Zadik7f441272018-01-22 11:48:23 +0000168 * \param key The encryption key.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500169 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000170 * \param keybits The size of data passed in bits. Valid options are:
171 * <ul><li>128 bits</li>
172 * <li>192 bits</li>
173 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000174 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100175 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100176 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000177 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200178MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200180 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000181
182/**
Rose Zadik7f441272018-01-22 11:48:23 +0000183 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000184 *
Rose Zadik7f441272018-01-22 11:48:23 +0000185 * \param ctx The AES context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500186 * It must be initialized.
Rose Zadik7f441272018-01-22 11:48:23 +0000187 * \param key The decryption key.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500188 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000189 * \param keybits The size of data passed. Valid options are:
190 * <ul><li>128 bits</li>
191 * <li>192 bits</li>
192 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000193 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100194 * \return \c 0 on success.
195 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000196 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200197MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200199 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000200
Jaeden Amero9366feb2018-05-29 18:55:17 +0100201#if defined(MBEDTLS_CIPHER_MODE_XTS)
202/**
203 * \brief This function prepares an XTS context for encryption and
204 * sets the encryption key.
205 *
206 * \param ctx The AES XTS context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500207 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100208 * \param key The encryption key. This is comprised of the XTS key1
209 * concatenated with the XTS key2.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500210 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100211 * \param keybits The size of \p key passed in bits. Valid options are:
212 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
213 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
214 *
215 * \return \c 0 on success.
216 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
217 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200218MBEDTLS_CHECK_RETURN_TYPICAL
Jaeden Amero9366feb2018-05-29 18:55:17 +0100219int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
220 const unsigned char *key,
221 unsigned int keybits );
222
223/**
224 * \brief This function prepares an XTS context for decryption and
225 * sets the decryption key.
226 *
227 * \param ctx The AES XTS context to which the key should be bound.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500228 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100229 * \param key The decryption key. This is comprised of the XTS key1
230 * concatenated with the XTS key2.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500231 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100232 * \param keybits The size of \p key passed in bits. Valid options are:
233 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
234 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
235 *
236 * \return \c 0 on success.
237 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
238 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200239MBEDTLS_CHECK_RETURN_TYPICAL
Jaeden Amero9366feb2018-05-29 18:55:17 +0100240int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
241 const unsigned char *key,
242 unsigned int keybits );
243#endif /* MBEDTLS_CIPHER_MODE_XTS */
244
Paul Bakker5121ce52009-01-03 21:22:43 +0000245/**
Rose Zadik7f441272018-01-22 11:48:23 +0000246 * \brief This function performs an AES single-block encryption or
247 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 *
Rose Zadik7f441272018-01-22 11:48:23 +0000249 * It performs the operation defined in the \p mode parameter
250 * (encrypt or decrypt), on the input data buffer defined in
251 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000252 *
Rose Zadik7f441272018-01-22 11:48:23 +0000253 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
254 * mbedtls_aes_setkey_dec() must be called before the first
255 * call to this API with the same context.
256 *
257 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500258 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000259 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
260 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500261 * \param input The buffer holding the input data.
262 * It must be readable and at least \c 16 Bytes long.
263 * \param output The buffer where the output data will be written.
264 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000265
266 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200268MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000270 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000271 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000272 unsigned char output[16] );
273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000275/**
Rose Zadik7f441272018-01-22 11:48:23 +0000276 * \brief This function performs an AES-CBC encryption or decryption operation
277 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000278 *
Rose Zadik7f441272018-01-22 11:48:23 +0000279 * It performs the operation defined in the \p mode
280 * parameter (encrypt/decrypt), on the input data buffer defined in
281 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000282 *
Rose Zadik7f441272018-01-22 11:48:23 +0000283 * It can be called as many times as needed, until all the input
284 * data is processed. mbedtls_aes_init(), and either
285 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
286 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000287 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500288 * \note This function operates on full blocks, that is, the input size
289 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000290 *
291 * \note Upon exit, the content of the IV is updated so that you can
292 * call the same function again on the next
293 * block(s) of data and get the same result as if it was
294 * encrypted in one call. This allows a "streaming" usage.
295 * If you need to retain the contents of the IV, you should
296 * either save it manually or use the cipher module instead.
297 *
298 *
299 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500300 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000301 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
302 * #MBEDTLS_AES_DECRYPT.
303 * \param length The length of the input data in Bytes. This must be a
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500304 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000305 * \param iv Initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500306 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000307 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500308 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000309 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500310 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000311 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100312 * \return \c 0 on success.
313 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000314 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000315 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200316MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000318 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000319 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000320 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000321 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000322 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000324
Aorimn5f778012016-06-09 23:22:58 +0200325#if defined(MBEDTLS_CIPHER_MODE_XTS)
326/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100327 * \brief This function performs an AES-XTS encryption or decryption
328 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200329 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100330 * AES-XTS encrypts or decrypts blocks based on their location as
331 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100332 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200333 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100334 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
335 * AES blocks. If the data unit is larger than this, this function
336 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
337 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100338 * \param ctx The AES XTS context to use for AES XTS operations.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500339 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100340 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
341 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500342 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100343 * length between 16 bytes and 2^24 bytes inclusive
344 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100345 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100346 * bytes in little-endian format. For disk encryption, this
347 * is typically the index of the block device sector that
348 * contains the data.
349 * \param input The buffer holding the input data (which is an entire
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500350 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100351 * input.
352 * \param output The buffer holding the output data (which is an entire
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500353 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100354 * output.
Aorimn5f778012016-06-09 23:22:58 +0200355 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100356 * \return \c 0 on success.
357 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500358 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100359 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200360 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200361MBEDTLS_CHECK_RETURN_TYPICAL
Jaeden Amero9366feb2018-05-29 18:55:17 +0100362int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
363 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100364 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100365 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100366 const unsigned char *input,
367 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200368#endif /* MBEDTLS_CIPHER_MODE_XTS */
369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000371/**
Rose Zadik7f441272018-01-22 11:48:23 +0000372 * \brief This function performs an AES-CFB128 encryption or decryption
373 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000374 *
Rose Zadik7f441272018-01-22 11:48:23 +0000375 * It performs the operation defined in the \p mode
376 * parameter (encrypt or decrypt), on the input data buffer
377 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000378 *
Rose Zadik7f441272018-01-22 11:48:23 +0000379 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
380 * regardless of whether you are performing an encryption or decryption
381 * operation, that is, regardless of the \p mode parameter. This is
382 * because CFB mode uses the same key schedule for encryption and
383 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000384 *
Rose Zadik7f441272018-01-22 11:48:23 +0000385 * \note Upon exit, the content of the IV is updated so that you can
386 * call the same function again on the next
387 * block(s) of data and get the same result as if it was
388 * encrypted in one call. This allows a "streaming" usage.
389 * If you need to retain the contents of the
390 * IV, you must either save it manually or use the cipher
391 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000392 *
Rose Zadik7f441272018-01-22 11:48:23 +0000393 *
394 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500395 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000396 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
397 * #MBEDTLS_AES_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500398 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000399 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500400 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000401 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500402 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000403 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500404 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000405 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500406 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000407 *
408 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000409 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200410MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200411int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000412 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000413 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000414 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000415 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000416 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000417 unsigned char *output );
418
Paul Bakker9a736322012-11-14 12:39:52 +0000419/**
Rose Zadik7f441272018-01-22 11:48:23 +0000420 * \brief This function performs an AES-CFB8 encryption or decryption
421 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100422 *
Rose Zadik7f441272018-01-22 11:48:23 +0000423 * It performs the operation defined in the \p mode
424 * parameter (encrypt/decrypt), on the input data buffer defined
425 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100426 *
Rose Zadik7f441272018-01-22 11:48:23 +0000427 * Due to the nature of CFB, you must use the same key schedule for
428 * both encryption and decryption operations. Therefore, you must
429 * use the context initialized with mbedtls_aes_setkey_enc() for
430 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000431 *
Rose Zadik7f441272018-01-22 11:48:23 +0000432 * \note Upon exit, the content of the IV is updated so that you can
433 * call the same function again on the next
434 * block(s) of data and get the same result as if it was
435 * encrypted in one call. This allows a "streaming" usage.
436 * If you need to retain the contents of the
437 * IV, you should either save it manually or use the cipher
438 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100439 *
Rose Zadik7f441272018-01-22 11:48:23 +0000440 *
441 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500442 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000443 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
444 * #MBEDTLS_AES_DECRYPT
445 * \param length The length of the input data.
446 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500447 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000448 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500449 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000450 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500451 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000452 *
453 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100454 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200455MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200456int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100457 int mode,
458 size_t length,
459 unsigned char iv[16],
460 const unsigned char *input,
461 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200462#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100463
Simon Butcher76a5b222018-04-22 22:57:27 +0100464#if defined(MBEDTLS_CIPHER_MODE_OFB)
465/**
Simon Butcher5db13622018-06-04 22:11:25 +0100466 * \brief This function performs an AES-OFB (Output Feedback Mode)
467 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100468 *
Simon Butcher5db13622018-06-04 22:11:25 +0100469 * For OFB, you must set up the context with
470 * mbedtls_aes_setkey_enc(), regardless of whether you are
471 * performing an encryption or decryption operation. This is
472 * because OFB mode uses the same key schedule for encryption and
473 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100474 *
Simon Butcher5db13622018-06-04 22:11:25 +0100475 * The OFB operation is identical for encryption or decryption,
476 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100477 *
Simon Butcher5db13622018-06-04 22:11:25 +0100478 * \note Upon exit, the content of iv, the Initialisation Vector, is
479 * updated so that you can call the same function again on the next
480 * block(s) of data and get the same result as if it was encrypted
481 * in one call. This allows a "streaming" usage, by initialising
482 * iv_off to 0 before the first call, and preserving its value
483 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100484 *
Simon Butcher5db13622018-06-04 22:11:25 +0100485 * For non-streaming use, the iv should be initialised on each call
486 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100487 *
Simon Butcher5db13622018-06-04 22:11:25 +0100488 * If you need to retain the contents of the initialisation vector,
489 * you must either save it manually or use the cipher module
490 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100491 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100492 * \warning For the OFB mode, the initialisation vector must be unique
493 * every encryption operation. Reuse of an initialisation vector
494 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100495 *
496 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500497 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100498 * \param length The length of the input data.
499 * \param iv_off The offset in IV (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500500 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100501 * \param iv The initialization vector (updated after use).
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500502 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100503 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500504 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100505 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500506 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100507 *
508 * \return \c 0 on success.
509 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200510MBEDTLS_CHECK_RETURN_TYPICAL
Simon Butcher76a5b222018-04-22 22:57:27 +0100511int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
512 size_t length,
513 size_t *iv_off,
514 unsigned char iv[16],
515 const unsigned char *input,
516 unsigned char *output );
517
518#endif /* MBEDTLS_CIPHER_MODE_OFB */
519
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200520#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100521/**
Rose Zadik7f441272018-01-22 11:48:23 +0000522 * \brief This function performs an AES-CTR encryption or decryption
523 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000524 *
Rose Zadik7f441272018-01-22 11:48:23 +0000525 * This function performs the operation defined in the \p mode
526 * parameter (encrypt/decrypt), on the input data buffer
527 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000528 *
Rose Zadik7f441272018-01-22 11:48:23 +0000529 * Due to the nature of CTR, you must use the same key schedule
530 * for both encryption and decryption operations. Therefore, you
531 * must use the context initialized with mbedtls_aes_setkey_enc()
532 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000533 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100534 * \warning You must never reuse a nonce value with the same key. Doing so
535 * would void the encryption for the two messages encrypted with
536 * the same nonce and key.
537 *
538 * There are two common strategies for managing nonces with CTR:
539 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200540 * 1. You can handle everything as a single message processed over
541 * successive calls to this function. In that case, you want to
542 * set \p nonce_counter and \p nc_off to 0 for the first call, and
543 * then preserve the values of \p nonce_counter, \p nc_off and \p
544 * stream_block across calls to this function as they will be
545 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100546 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200547 * With this strategy, you must not encrypt more than 2**128
548 * blocks of data with the same key.
549 *
550 * 2. You can encrypt separate messages by dividing the \p
551 * nonce_counter buffer in two areas: the first one used for a
552 * per-message nonce, handled by yourself, and the second one
553 * updated by this function internally.
554 *
555 * For example, you might reserve the first 12 bytes for the
556 * per-message nonce, and the last 4 bytes for internal use. In that
557 * case, before calling this function on a new message you need to
558 * set the first 12 bytes of \p nonce_counter to your chosen nonce
559 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
560 * stream_block to be ignored). That way, you can encrypt at most
561 * 2**96 messages of up to 2**32 blocks each with the same key.
562 *
563 * The per-message nonce (or information sufficient to reconstruct
564 * it) needs to be communicated with the ciphertext and must be unique.
565 * The recommended way to ensure uniqueness is to use a message
566 * counter. An alternative is to generate random nonces, but this
567 * limits the number of messages that can be securely encrypted:
568 * for example, with 96-bit random nonces, you should not encrypt
569 * more than 2**32 messages with the same key.
570 *
571 * Note that for both stategies, sizes are measured in blocks and
572 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000573 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200574 * \warning Upon return, \p stream_block contains sensitive data. Its
575 * content must not be written to insecure storage and should be
576 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000577 *
Rose Zadik7f441272018-01-22 11:48:23 +0000578 * \param ctx The AES context to use for encryption or decryption.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500579 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000580 * \param length The length of the input data.
581 * \param nc_off The offset in the current \p stream_block, for
582 * resuming within the current cipher stream. The
583 * offset pointer should be 0 at the start of a stream.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500584 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000585 * \param nonce_counter The 128-bit nonce and counter.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500586 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000587 * \param stream_block The saved stream block for resuming. This is
588 * overwritten by the function.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500589 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000590 * \param input The buffer holding the input data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500591 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000592 * \param output The buffer holding the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500593 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000594 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100595 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000596 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200597MBEDTLS_CHECK_RETURN_TYPICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000599 size_t length,
600 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000601 unsigned char nonce_counter[16],
602 unsigned char stream_block[16],
603 const unsigned char *input,
604 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200606
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200607/**
Rose Zadik7f441272018-01-22 11:48:23 +0000608 * \brief Internal AES block encryption function. This is only
609 * exposed to allow overriding it using
610 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200611 *
Rose Zadik7f441272018-01-22 11:48:23 +0000612 * \param ctx The AES context to use for encryption.
613 * \param input The plaintext block.
614 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000615 *
Rose Zadik7f441272018-01-22 11:48:23 +0000616 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200617 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200618MBEDTLS_CHECK_RETURN_TYPICAL
Andres AGf5bf7182017-03-03 14:09:56 +0000619int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
620 const unsigned char input[16],
621 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200622
623/**
Rose Zadik7f441272018-01-22 11:48:23 +0000624 * \brief Internal AES block decryption function. This is only
625 * exposed to allow overriding it using see
626 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200627 *
Rose Zadik7f441272018-01-22 11:48:23 +0000628 * \param ctx The AES context to use for decryption.
629 * \param input The ciphertext block.
630 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000631 *
Rose Zadik7f441272018-01-22 11:48:23 +0000632 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200633 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200634MBEDTLS_CHECK_RETURN_TYPICAL
Andres AGf5bf7182017-03-03 14:09:56 +0000635int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
636 const unsigned char input[16],
637 unsigned char output[16] );
638
639#if !defined(MBEDTLS_DEPRECATED_REMOVED)
640#if defined(MBEDTLS_DEPRECATED_WARNING)
641#define MBEDTLS_DEPRECATED __attribute__((deprecated))
642#else
643#define MBEDTLS_DEPRECATED
644#endif
645/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100646 * \brief Deprecated internal AES block encryption function
647 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000648 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500649 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000650 *
Rose Zadik7f441272018-01-22 11:48:23 +0000651 * \param ctx The AES context to use for encryption.
652 * \param input Plaintext block.
653 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000654 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100655MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
656 const unsigned char input[16],
657 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000658
659/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100660 * \brief Deprecated internal AES block decryption function
661 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000662 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500663 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000664 *
Rose Zadik7f441272018-01-22 11:48:23 +0000665 * \param ctx The AES context to use for decryption.
666 * \param input Ciphertext block.
667 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000668 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100669MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
670 const unsigned char input[16],
671 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000672
673#undef MBEDTLS_DEPRECATED
674#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200675
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500676
677#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000678/**
Rose Zadik7f441272018-01-22 11:48:23 +0000679 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000680 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100681 * \return \c 0 on success.
682 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000683 */
Gilles Peskinece555e42021-09-23 17:35:37 +0200684MBEDTLS_CHECK_RETURN_CRITICAL
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000686
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500687#endif /* MBEDTLS_SELF_TEST */
688
Paul Bakker5121ce52009-01-03 21:22:43 +0000689#ifdef __cplusplus
690}
691#endif
692
693#endif /* aes.h */