blob: 5fb020fa88ecb67e7f1f9d28f4b69e153ef14e2d [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
Rose Zadik7f441272018-01-22 11:48:23 +000023/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020024 * SPDX-License-Identifier: Apache-2.0
25 *
26 * Licensed under the Apache License, Version 2.0 (the "License"); you may
27 * not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
34 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000037 *
Rose Zadik7f441272018-01-22 11:48:23 +000038 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000039 */
Rose Zadik7f441272018-01-22 11:48:23 +000040
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#ifndef MBEDTLS_AES_H
42#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000043
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020045#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020046#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020048#endif
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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
59#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000060
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000061/* Error codes in range 0x0021-0x0025 */
62#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030063
64/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Rose Zadik7f441272018-01-22 11:48:23 +000065#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030066
67/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010068#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000069
Andres AGf5bf7182017-03-03 14:09:56 +000070#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
71 !defined(inline) && !defined(__cplusplus)
72#define inline __inline
73#endif
74
Paul Bakker407a0da2013-06-27 14:29:21 +020075#ifdef __cplusplus
76extern "C" {
77#endif
78
Ron Eldorb2aacec2017-05-18 16:53:08 +030079#if !defined(MBEDTLS_AES_ALT)
80// Regular implementation
81//
82
Paul Bakker5121ce52009-01-03 21:22:43 +000083/**
Rose Zadik7f441272018-01-22 11:48:23 +000084 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000085 */
Dawid Drozd428cc522018-07-24 10:02:47 +020086typedef struct mbedtls_aes_context
Paul Bakker5121ce52009-01-03 21:22:43 +000087{
Rose Zadik7f441272018-01-22 11:48:23 +000088 int nr; /*!< The number of rounds. */
89 uint32_t *rk; /*!< AES round keys. */
Andrzej Kurekfac2f9b2020-07-19 00:32:34 -040090#if defined(MBEDTLS_AES_SCA_COUNTERMEASURES)
Andrzej Kureke78775e2020-07-02 10:57:00 -040091 uint32_t frk[8]; /*!< Fake AES round keys. */
Andrzej Kurekfac2f9b2020-07-19 00:32:34 -040092#endif
Andrzej Kurekfba59212020-08-07 21:02:25 -040093#if defined(MBEDTLS_VALIDATE_AES_KEYS_INTEGRITY)
94 uint16_t crc; /*!< CRC-16 of the set key */
95#endif
Arto Kinnunen5ed870d2019-10-21 09:27:55 +030096#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
97 uint32_t buf[44]; /*!< Unaligned data buffer */
98#else /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Rose Zadik7f441272018-01-22 11:48:23 +000099 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
100 hold 32 extra Bytes, which can be used for
101 one of the following purposes:
102 <ul><li>Alignment if VIA padlock is
103 used.</li>
104 <li>Simplifying key expansion in the 256-bit
105 case by generating an extra round key.
106 </li></ul> */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300107#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Paul Bakker5121ce52009-01-03 21:22:43 +0000108}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000110
Jaeden Amero9366feb2018-05-29 18:55:17 +0100111#if defined(MBEDTLS_CIPHER_MODE_XTS)
112/**
113 * \brief The AES XTS context-type definition.
114 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200115typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100116{
117 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
118 encryption or decryption. */
119 mbedtls_aes_context tweak; /*!< The AES context used for tweak
120 computation. */
121} mbedtls_aes_xts_context;
122#endif /* MBEDTLS_CIPHER_MODE_XTS */
123
Ron Eldorb2aacec2017-05-18 16:53:08 +0300124#else /* MBEDTLS_AES_ALT */
125#include "aes_alt.h"
126#endif /* MBEDTLS_AES_ALT */
127
Paul Bakker5121ce52009-01-03 21:22:43 +0000128/**
Rose Zadik7f441272018-01-22 11:48:23 +0000129 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200130 *
Rose Zadik7f441272018-01-22 11:48:23 +0000131 * It must be the first API called before using
132 * the context.
133 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100134 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200135 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200137
138/**
Rose Zadik7f441272018-01-22 11:48:23 +0000139 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200140 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100141 * \param ctx The AES context to clear.
142 * If this is \c NULL, this function does nothing.
143 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200144 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200146
Jaeden Amero9366feb2018-05-29 18:55:17 +0100147#if defined(MBEDTLS_CIPHER_MODE_XTS)
148/**
149 * \brief This function initializes the specified AES XTS context.
150 *
151 * It must be the first API called before using
152 * the context.
153 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100154 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100155 */
156void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
157
158/**
159 * \brief This function releases and clears the specified AES XTS context.
160 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100161 * \param ctx The AES XTS context to clear.
162 * If this is \c NULL, this function does nothing.
163 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100164 */
165void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
166#endif /* MBEDTLS_CIPHER_MODE_XTS */
167
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200168/**
Rose Zadik7f441272018-01-22 11:48:23 +0000169 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000170 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100171 * \param ctx The AES context to which the key should be bound.
172 * It must be initialized.
173 * \param key The encryption key.
174 * 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 in bits. 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.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200181 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
182 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000183 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200185 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000186
187/**
Rose Zadik7f441272018-01-22 11:48:23 +0000188 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000189 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100190 * \param ctx The AES context to which the key should be bound.
191 * It must be initialized.
192 * \param key The decryption key.
193 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000194 * \param keybits The size of data passed. Valid options are:
195 * <ul><li>128 bits</li>
196 * <li>192 bits</li>
197 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000198 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100199 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200200 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
201 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000202 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200204 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000205
Jaeden Amero9366feb2018-05-29 18:55:17 +0100206#if defined(MBEDTLS_CIPHER_MODE_XTS)
207/**
208 * \brief This function prepares an XTS context for encryption and
209 * sets the encryption key.
210 *
211 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100212 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100213 * \param key The encryption key. This is comprised of the XTS key1
214 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100215 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100216 * \param keybits The size of \p key passed in bits. Valid options are:
217 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
218 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
219 *
220 * \return \c 0 on success.
221 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
222 */
223int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
224 const unsigned char *key,
225 unsigned int keybits );
226
227/**
228 * \brief This function prepares an XTS context for decryption and
229 * sets the decryption key.
230 *
231 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100232 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100233 * \param key The decryption key. This is comprised of the XTS key1
234 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100235 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100236 * \param keybits The size of \p key passed in bits. Valid options are:
237 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
238 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
239 *
240 * \return \c 0 on success.
241 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
242 */
243int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
244 const unsigned char *key,
245 unsigned int keybits );
246#endif /* MBEDTLS_CIPHER_MODE_XTS */
247
Paul Bakker5121ce52009-01-03 21:22:43 +0000248/**
Rose Zadik7f441272018-01-22 11:48:23 +0000249 * \brief This function performs an AES single-block encryption or
250 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000251 *
Rose Zadik7f441272018-01-22 11:48:23 +0000252 * It performs the operation defined in the \p mode parameter
253 * (encrypt or decrypt), on the input data buffer defined in
254 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000255 *
Rose Zadik7f441272018-01-22 11:48:23 +0000256 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
257 * mbedtls_aes_setkey_dec() must be called before the first
258 * call to this API with the same context.
259 *
260 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100261 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000262 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
263 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100264 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100265 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100266 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100267 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000268
269 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000270 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000272 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000273 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000274 unsigned char output[16] );
275
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000277/**
Rose Zadik7f441272018-01-22 11:48:23 +0000278 * \brief This function performs an AES-CBC encryption or decryption operation
279 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000280 *
Rose Zadik7f441272018-01-22 11:48:23 +0000281 * It performs the operation defined in the \p mode
282 * parameter (encrypt/decrypt), on the input data buffer defined in
283 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000284 *
Rose Zadik7f441272018-01-22 11:48:23 +0000285 * It can be called as many times as needed, until all the input
286 * data is processed. mbedtls_aes_init(), and either
287 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
288 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000289 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100290 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100291 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000292 *
293 * \note Upon exit, the content of the IV is updated so that you can
294 * call the same function again on the next
295 * block(s) of data and get the same result as if it was
296 * encrypted in one call. This allows a "streaming" usage.
297 * If you need to retain the contents of the IV, you should
298 * either save it manually or use the cipher module instead.
299 *
300 *
301 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100302 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000303 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
304 * #MBEDTLS_AES_DECRYPT.
305 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100306 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000307 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100308 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000309 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100310 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000311 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100312 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000313 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100314 * \return \c 0 on success.
315 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000316 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000317 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000319 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000320 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000321 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000322 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000323 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000325
Aorimn5f778012016-06-09 23:22:58 +0200326#if defined(MBEDTLS_CIPHER_MODE_XTS)
327/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100328 * \brief This function performs an AES-XTS encryption or decryption
329 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200330 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100331 * AES-XTS encrypts or decrypts blocks based on their location as
332 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100333 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200334 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100335 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
336 * AES blocks. If the data unit is larger than this, this function
337 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
338 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100339 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100340 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100341 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
342 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100343 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100344 * length between 16 bytes and 2^24 bytes inclusive
345 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100346 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100347 * bytes in little-endian format. For disk encryption, this
348 * is typically the index of the block device sector that
349 * contains the data.
350 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100351 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100352 * input.
353 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100354 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100355 * output.
Aorimn5f778012016-06-09 23:22:58 +0200356 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100357 * \return \c 0 on success.
358 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100359 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100360 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200361 */
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.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100395 * 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.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100398 * \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).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100400 * 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).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100402 * 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.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100404 * 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.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100406 * 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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200410int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000411 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000412 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000413 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000414 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000415 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000416 unsigned char *output );
417
Paul Bakker9a736322012-11-14 12:39:52 +0000418/**
Rose Zadik7f441272018-01-22 11:48:23 +0000419 * \brief This function performs an AES-CFB8 encryption or decryption
420 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100421 *
Rose Zadik7f441272018-01-22 11:48:23 +0000422 * It performs the operation defined in the \p mode
423 * parameter (encrypt/decrypt), on the input data buffer defined
424 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100425 *
Rose Zadik7f441272018-01-22 11:48:23 +0000426 * Due to the nature of CFB, you must use the same key schedule for
427 * both encryption and decryption operations. Therefore, you must
428 * use the context initialized with mbedtls_aes_setkey_enc() for
429 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000430 *
Rose Zadik7f441272018-01-22 11:48:23 +0000431 * \note Upon exit, the content of the IV is updated so that you can
432 * call the same function again on the next
433 * block(s) of data and get the same result as if it was
434 * encrypted in one call. This allows a "streaming" usage.
435 * If you need to retain the contents of the
436 * IV, you should either save it manually or use the cipher
437 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100438 *
Rose Zadik7f441272018-01-22 11:48:23 +0000439 *
440 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100441 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000442 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
443 * #MBEDTLS_AES_DECRYPT
444 * \param length The length of the input data.
445 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100446 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000447 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100448 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000449 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100450 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000451 *
452 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100453 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200454int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100455 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.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100495 * 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).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100498 * 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).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100500 * 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.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100502 * 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.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100504 * 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 */
508int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
509 size_t length,
510 size_t *iv_off,
511 unsigned char iv[16],
512 const unsigned char *input,
513 unsigned char *output );
514
515#endif /* MBEDTLS_CIPHER_MODE_OFB */
516
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200517#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100518/**
Rose Zadik7f441272018-01-22 11:48:23 +0000519 * \brief This function performs an AES-CTR encryption or decryption
520 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000521 *
Rose Zadik7f441272018-01-22 11:48:23 +0000522 * This function performs the operation defined in the \p mode
523 * parameter (encrypt/decrypt), on the input data buffer
524 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000525 *
Rose Zadik7f441272018-01-22 11:48:23 +0000526 * Due to the nature of CTR, you must use the same key schedule
527 * for both encryption and decryption operations. Therefore, you
528 * must use the context initialized with mbedtls_aes_setkey_enc()
529 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000530 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100531 * \warning You must never reuse a nonce value with the same key. Doing so
532 * would void the encryption for the two messages encrypted with
533 * the same nonce and key.
534 *
535 * There are two common strategies for managing nonces with CTR:
536 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200537 * 1. You can handle everything as a single message processed over
538 * successive calls to this function. In that case, you want to
539 * set \p nonce_counter and \p nc_off to 0 for the first call, and
540 * then preserve the values of \p nonce_counter, \p nc_off and \p
541 * stream_block across calls to this function as they will be
542 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100543 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200544 * With this strategy, you must not encrypt more than 2**128
545 * blocks of data with the same key.
546 *
547 * 2. You can encrypt separate messages by dividing the \p
548 * nonce_counter buffer in two areas: the first one used for a
549 * per-message nonce, handled by yourself, and the second one
550 * updated by this function internally.
551 *
552 * For example, you might reserve the first 12 bytes for the
553 * per-message nonce, and the last 4 bytes for internal use. In that
554 * case, before calling this function on a new message you need to
555 * set the first 12 bytes of \p nonce_counter to your chosen nonce
556 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
557 * stream_block to be ignored). That way, you can encrypt at most
558 * 2**96 messages of up to 2**32 blocks each with the same key.
559 *
560 * The per-message nonce (or information sufficient to reconstruct
561 * it) needs to be communicated with the ciphertext and must be unique.
562 * The recommended way to ensure uniqueness is to use a message
563 * counter. An alternative is to generate random nonces, but this
564 * limits the number of messages that can be securely encrypted:
565 * for example, with 96-bit random nonces, you should not encrypt
566 * more than 2**32 messages with the same key.
567 *
568 * Note that for both stategies, sizes are measured in blocks and
569 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000570 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200571 * \warning Upon return, \p stream_block contains sensitive data. Its
572 * content must not be written to insecure storage and should be
573 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000574 *
Rose Zadik7f441272018-01-22 11:48:23 +0000575 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100576 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000577 * \param length The length of the input data.
578 * \param nc_off The offset in the current \p stream_block, for
579 * resuming within the current cipher stream. The
580 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100581 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000582 * \param nonce_counter The 128-bit nonce and counter.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100583 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000584 * \param stream_block The saved stream block for resuming. This is
585 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100586 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000587 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100588 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000589 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100590 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000591 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100592 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000593 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200594int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000595 size_t length,
596 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000597 unsigned char nonce_counter[16],
598 unsigned char stream_block[16],
599 const unsigned char *input,
600 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200602
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200603/**
Rose Zadik7f441272018-01-22 11:48:23 +0000604 * \brief Internal AES block encryption function. This is only
605 * exposed to allow overriding it using
606 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200607 *
Rose Zadik7f441272018-01-22 11:48:23 +0000608 * \param ctx The AES context to use for encryption.
609 * \param input The plaintext block.
610 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000611 *
Rose Zadik7f441272018-01-22 11:48:23 +0000612 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200613 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200614 */
Andres AGf5bf7182017-03-03 14:09:56 +0000615int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
616 const unsigned char input[16],
617 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200618
619/**
Rose Zadik7f441272018-01-22 11:48:23 +0000620 * \brief Internal AES block decryption function. This is only
621 * exposed to allow overriding it using see
622 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200623 *
Rose Zadik7f441272018-01-22 11:48:23 +0000624 * \param ctx The AES context to use for decryption.
625 * \param input The ciphertext block.
626 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000627 *
Rose Zadik7f441272018-01-22 11:48:23 +0000628 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200629 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200630 */
Andres AGf5bf7182017-03-03 14:09:56 +0000631int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
632 const unsigned char input[16],
633 unsigned char output[16] );
634
635#if !defined(MBEDTLS_DEPRECATED_REMOVED)
636#if defined(MBEDTLS_DEPRECATED_WARNING)
637#define MBEDTLS_DEPRECATED __attribute__((deprecated))
638#else
639#define MBEDTLS_DEPRECATED
640#endif
641/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100642 * \brief Deprecated internal AES block encryption function
643 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000644 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100645 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000646 *
Rose Zadik7f441272018-01-22 11:48:23 +0000647 * \param ctx The AES context to use for encryption.
648 * \param input Plaintext block.
649 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000650 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100651MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
652 const unsigned char input[16],
653 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000654
655/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100656 * \brief Deprecated internal AES block decryption function
657 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000658 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100659 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000660 *
Rose Zadik7f441272018-01-22 11:48:23 +0000661 * \param ctx The AES context to use for decryption.
662 * \param input Ciphertext block.
663 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000664 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100665MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
666 const unsigned char input[16],
667 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000668
669#undef MBEDTLS_DEPRECATED
670#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200671
Ron Eldorfa8f6352017-06-20 15:48:46 +0300672
673#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000674/**
Rose Zadik7f441272018-01-22 11:48:23 +0000675 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000676 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100677 * \return \c 0 on success.
678 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000679 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000681
Ron Eldorfa8f6352017-06-20 15:48:46 +0300682#endif /* MBEDTLS_SELF_TEST */
683
Paul Bakker5121ce52009-01-03 21:22:43 +0000684#ifdef __cplusplus
685}
686#endif
687
688#endif /* aes.h */