blob: 4468b6623ac2a10b67353a4341d6e3e48d36181d [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útif744bd72020-06-05 13:02:18 +020023/*
Bence Szépkútia2947ac2020-08-19 16:37:36 +020024 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +020025 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
26 *
27 * This file is provided under the Apache License 2.0, or the
28 * GNU General Public License v2.0 or later.
29 *
30 * **********
31 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020032 *
33 * Licensed under the Apache License, Version 2.0 (the "License"); you may
34 * not use this file except in compliance with the License.
35 * You may obtain a copy of the License at
36 *
37 * http://www.apache.org/licenses/LICENSE-2.0
38 *
39 * Unless required by applicable law or agreed to in writing, software
40 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
41 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42 * See the License for the specific language governing permissions and
43 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000044 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020045 * **********
46 *
47 * **********
48 * GNU General Public License v2.0 or later:
49 *
50 * This program is free software; you can redistribute it and/or modify
51 * it under the terms of the GNU General Public License as published by
52 * the Free Software Foundation; either version 2 of the License, or
53 * (at your option) any later version.
54 *
55 * This program is distributed in the hope that it will be useful,
56 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58 * GNU General Public License for more details.
59 *
60 * You should have received a copy of the GNU General Public License along
61 * with this program; if not, write to the Free Software Foundation, Inc.,
62 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
63 *
64 * **********
Paul Bakker5121ce52009-01-03 21:22:43 +000065 */
Rose Zadik7f441272018-01-22 11:48:23 +000066
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#ifndef MBEDTLS_AES_H
68#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000069
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020071#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020072#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020074#endif
Paul Bakker90995b52013-06-24 19:20:35 +020075
Rich Evans00ab4702015-02-06 13:43:58 +000076#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020077#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000078
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010079/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000080#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
81#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000082
Andres Amaya Garciac5380642017-11-28 19:57:51 +000083/* Error codes in range 0x0020-0x0022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
85#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000086
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000087/* Error codes in range 0x0021-0x0025 */
88#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030089
90/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Rose Zadik7f441272018-01-22 11:48:23 +000091#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030092
93/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010094#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000095
Andres AGf5bf7182017-03-03 14:09:56 +000096#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
97 !defined(inline) && !defined(__cplusplus)
98#define inline __inline
99#endif
100
Paul Bakker407a0da2013-06-27 14:29:21 +0200101#ifdef __cplusplus
102extern "C" {
103#endif
104
Ron Eldorb2aacec2017-05-18 16:53:08 +0300105#if !defined(MBEDTLS_AES_ALT)
106// Regular implementation
107//
108
Paul Bakker5121ce52009-01-03 21:22:43 +0000109/**
Rose Zadik7f441272018-01-22 11:48:23 +0000110 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +0000111 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200112typedef struct mbedtls_aes_context
Paul Bakker5121ce52009-01-03 21:22:43 +0000113{
Rose Zadik7f441272018-01-22 11:48:23 +0000114 int nr; /*!< The number of rounds. */
115 uint32_t *rk; /*!< AES round keys. */
116 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
117 hold 32 extra Bytes, which can be used for
118 one of the following purposes:
119 <ul><li>Alignment if VIA padlock is
120 used.</li>
121 <li>Simplifying key expansion in the 256-bit
122 case by generating an extra round key.
123 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +0000124}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000126
Jaeden Amero9366feb2018-05-29 18:55:17 +0100127#if defined(MBEDTLS_CIPHER_MODE_XTS)
128/**
129 * \brief The AES XTS context-type definition.
130 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200131typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100132{
133 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
134 encryption or decryption. */
135 mbedtls_aes_context tweak; /*!< The AES context used for tweak
136 computation. */
137} mbedtls_aes_xts_context;
138#endif /* MBEDTLS_CIPHER_MODE_XTS */
139
Ron Eldorb2aacec2017-05-18 16:53:08 +0300140#else /* MBEDTLS_AES_ALT */
141#include "aes_alt.h"
142#endif /* MBEDTLS_AES_ALT */
143
Paul Bakker5121ce52009-01-03 21:22:43 +0000144/**
Rose Zadik7f441272018-01-22 11:48:23 +0000145 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200146 *
Rose Zadik7f441272018-01-22 11:48:23 +0000147 * It must be the first API called before using
148 * the context.
149 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100150 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200151 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200153
154/**
Rose Zadik7f441272018-01-22 11:48:23 +0000155 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200156 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100157 * \param ctx The AES context to clear.
158 * If this is \c NULL, this function does nothing.
159 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200160 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200162
Jaeden Amero9366feb2018-05-29 18:55:17 +0100163#if defined(MBEDTLS_CIPHER_MODE_XTS)
164/**
165 * \brief This function initializes the specified AES XTS context.
166 *
167 * It must be the first API called before using
168 * the context.
169 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100170 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100171 */
172void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
173
174/**
175 * \brief This function releases and clears the specified AES XTS context.
176 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100177 * \param ctx The AES XTS context to clear.
178 * If this is \c NULL, this function does nothing.
179 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100180 */
181void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
182#endif /* MBEDTLS_CIPHER_MODE_XTS */
183
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200184/**
Rose Zadik7f441272018-01-22 11:48:23 +0000185 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000186 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100187 * \param ctx The AES context to which the key should be bound.
188 * It must be initialized.
189 * \param key The encryption key.
190 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000191 * \param keybits The size of data passed in bits. Valid options are:
192 * <ul><li>128 bits</li>
193 * <li>192 bits</li>
194 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000195 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100196 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100197 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000198 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200200 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000201
202/**
Rose Zadik7f441272018-01-22 11:48:23 +0000203 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000204 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100205 * \param ctx The AES context to which the key should be bound.
206 * It must be initialized.
207 * \param key The decryption key.
208 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000209 * \param keybits The size of data passed. Valid options are:
210 * <ul><li>128 bits</li>
211 * <li>192 bits</li>
212 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000213 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100214 * \return \c 0 on success.
215 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000216 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200218 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000219
Jaeden Amero9366feb2018-05-29 18:55:17 +0100220#if defined(MBEDTLS_CIPHER_MODE_XTS)
221/**
222 * \brief This function prepares an XTS context for encryption and
223 * sets the encryption key.
224 *
225 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100226 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100227 * \param key The encryption key. This is comprised of the XTS key1
228 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100229 * 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 */
237int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
238 const unsigned char *key,
239 unsigned int keybits );
240
241/**
242 * \brief This function prepares an XTS context for decryption and
243 * sets the decryption key.
244 *
245 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100246 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100247 * \param key The decryption key. This is comprised of the XTS key1
248 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100249 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100250 * \param keybits The size of \p key passed in bits. Valid options are:
251 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
252 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
253 *
254 * \return \c 0 on success.
255 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
256 */
257int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
258 const unsigned char *key,
259 unsigned int keybits );
260#endif /* MBEDTLS_CIPHER_MODE_XTS */
261
Paul Bakker5121ce52009-01-03 21:22:43 +0000262/**
Rose Zadik7f441272018-01-22 11:48:23 +0000263 * \brief This function performs an AES single-block encryption or
264 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000265 *
Rose Zadik7f441272018-01-22 11:48:23 +0000266 * It performs the operation defined in the \p mode parameter
267 * (encrypt or decrypt), on the input data buffer defined in
268 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000269 *
Rose Zadik7f441272018-01-22 11:48:23 +0000270 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
271 * mbedtls_aes_setkey_dec() must be called before the first
272 * call to this API with the same context.
273 *
274 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100275 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000276 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
277 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100278 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100279 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100280 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100281 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000282
283 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000284 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000286 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000287 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000288 unsigned char output[16] );
289
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000291/**
Rose Zadik7f441272018-01-22 11:48:23 +0000292 * \brief This function performs an AES-CBC encryption or decryption operation
293 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000294 *
Rose Zadik7f441272018-01-22 11:48:23 +0000295 * It performs the operation defined in the \p mode
296 * parameter (encrypt/decrypt), on the input data buffer defined in
297 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000298 *
Rose Zadik7f441272018-01-22 11:48:23 +0000299 * It can be called as many times as needed, until all the input
300 * data is processed. mbedtls_aes_init(), and either
301 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
302 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000303 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100304 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100305 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000306 *
307 * \note Upon exit, the content of the IV is updated so that you can
308 * call the same function again on the next
309 * block(s) of data and get the same result as if it was
310 * encrypted in one call. This allows a "streaming" usage.
311 * If you need to retain the contents of the IV, you should
312 * either save it manually or use the cipher module instead.
313 *
314 *
315 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100316 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000317 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
318 * #MBEDTLS_AES_DECRYPT.
319 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100320 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000321 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100322 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000323 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100324 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000325 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100326 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000327 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100328 * \return \c 0 on success.
329 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000330 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000331 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000333 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000334 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000335 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000336 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000337 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000339
Aorimn5f778012016-06-09 23:22:58 +0200340#if defined(MBEDTLS_CIPHER_MODE_XTS)
341/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100342 * \brief This function performs an AES-XTS encryption or decryption
343 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200344 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100345 * AES-XTS encrypts or decrypts blocks based on their location as
346 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100347 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200348 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100349 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
350 * AES blocks. If the data unit is larger than this, this function
351 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
352 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100353 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100354 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100355 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
356 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100357 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100358 * length between 16 bytes and 2^24 bytes inclusive
359 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100360 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100361 * bytes in little-endian format. For disk encryption, this
362 * is typically the index of the block device sector that
363 * contains the data.
364 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100365 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100366 * input.
367 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100368 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100369 * output.
Aorimn5f778012016-06-09 23:22:58 +0200370 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100371 * \return \c 0 on success.
372 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100373 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100374 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200375 */
Jaeden Amero9366feb2018-05-29 18:55:17 +0100376int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
377 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100378 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100379 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100380 const unsigned char *input,
381 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200382#endif /* MBEDTLS_CIPHER_MODE_XTS */
383
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200384#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000385/**
Rose Zadik7f441272018-01-22 11:48:23 +0000386 * \brief This function performs an AES-CFB128 encryption or decryption
387 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000388 *
Rose Zadik7f441272018-01-22 11:48:23 +0000389 * It performs the operation defined in the \p mode
390 * parameter (encrypt or decrypt), on the input data buffer
391 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000392 *
Rose Zadik7f441272018-01-22 11:48:23 +0000393 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
394 * regardless of whether you are performing an encryption or decryption
395 * operation, that is, regardless of the \p mode parameter. This is
396 * because CFB mode uses the same key schedule for encryption and
397 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000398 *
Rose Zadik7f441272018-01-22 11:48:23 +0000399 * \note Upon exit, the content of the IV is updated so that you can
400 * call the same function again on the next
401 * block(s) of data and get the same result as if it was
402 * encrypted in one call. This allows a "streaming" usage.
403 * If you need to retain the contents of the
404 * IV, you must either save it manually or use the cipher
405 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000406 *
Rose Zadik7f441272018-01-22 11:48:23 +0000407 *
408 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100409 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000410 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
411 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100412 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000413 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100414 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000415 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100416 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000417 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100418 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000419 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100420 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000421 *
422 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000423 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200424int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000425 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000426 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000427 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000428 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000429 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000430 unsigned char *output );
431
Paul Bakker9a736322012-11-14 12:39:52 +0000432/**
Rose Zadik7f441272018-01-22 11:48:23 +0000433 * \brief This function performs an AES-CFB8 encryption or decryption
434 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100435 *
Rose Zadik7f441272018-01-22 11:48:23 +0000436 * It performs the operation defined in the \p mode
437 * parameter (encrypt/decrypt), on the input data buffer defined
438 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100439 *
Rose Zadik7f441272018-01-22 11:48:23 +0000440 * Due to the nature of CFB, you must use the same key schedule for
441 * both encryption and decryption operations. Therefore, you must
442 * use the context initialized with mbedtls_aes_setkey_enc() for
443 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000444 *
Rose Zadik7f441272018-01-22 11:48:23 +0000445 * \note Upon exit, the content of the IV is updated so that you can
446 * call the same function again on the next
447 * block(s) of data and get the same result as if it was
448 * encrypted in one call. This allows a "streaming" usage.
449 * If you need to retain the contents of the
450 * IV, you should either save it manually or use the cipher
451 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100452 *
Rose Zadik7f441272018-01-22 11:48:23 +0000453 *
454 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100455 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000456 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
457 * #MBEDTLS_AES_DECRYPT
458 * \param length The length of the input data.
459 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100460 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000461 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100462 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000463 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100464 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000465 *
466 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100467 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100469 int mode,
470 size_t length,
471 unsigned char iv[16],
472 const unsigned char *input,
473 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200474#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100475
Simon Butcher76a5b222018-04-22 22:57:27 +0100476#if defined(MBEDTLS_CIPHER_MODE_OFB)
477/**
Simon Butcher5db13622018-06-04 22:11:25 +0100478 * \brief This function performs an AES-OFB (Output Feedback Mode)
479 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100480 *
Simon Butcher5db13622018-06-04 22:11:25 +0100481 * For OFB, you must set up the context with
482 * mbedtls_aes_setkey_enc(), regardless of whether you are
483 * performing an encryption or decryption operation. This is
484 * because OFB mode uses the same key schedule for encryption and
485 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100486 *
Simon Butcher5db13622018-06-04 22:11:25 +0100487 * The OFB operation is identical for encryption or decryption,
488 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100489 *
Simon Butcher5db13622018-06-04 22:11:25 +0100490 * \note Upon exit, the content of iv, the Initialisation Vector, is
491 * updated so that you can call the same function again on the next
492 * block(s) of data and get the same result as if it was encrypted
493 * in one call. This allows a "streaming" usage, by initialising
494 * iv_off to 0 before the first call, and preserving its value
495 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100496 *
Simon Butcher5db13622018-06-04 22:11:25 +0100497 * For non-streaming use, the iv should be initialised on each call
498 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100499 *
Simon Butcher5db13622018-06-04 22:11:25 +0100500 * If you need to retain the contents of the initialisation vector,
501 * you must either save it manually or use the cipher module
502 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100503 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100504 * \warning For the OFB mode, the initialisation vector must be unique
505 * every encryption operation. Reuse of an initialisation vector
506 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100507 *
508 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100509 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100510 * \param length The length of the input data.
511 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100512 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100513 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100514 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100515 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100516 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100517 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100518 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100519 *
520 * \return \c 0 on success.
521 */
522int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
523 size_t length,
524 size_t *iv_off,
525 unsigned char iv[16],
526 const unsigned char *input,
527 unsigned char *output );
528
529#endif /* MBEDTLS_CIPHER_MODE_OFB */
530
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200531#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100532/**
Rose Zadik7f441272018-01-22 11:48:23 +0000533 * \brief This function performs an AES-CTR encryption or decryption
534 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000535 *
Rose Zadik7f441272018-01-22 11:48:23 +0000536 * This function performs the operation defined in the \p mode
537 * parameter (encrypt/decrypt), on the input data buffer
538 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000539 *
Rose Zadik7f441272018-01-22 11:48:23 +0000540 * Due to the nature of CTR, you must use the same key schedule
541 * for both encryption and decryption operations. Therefore, you
542 * must use the context initialized with mbedtls_aes_setkey_enc()
543 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000544 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100545 * \warning You must never reuse a nonce value with the same key. Doing so
546 * would void the encryption for the two messages encrypted with
547 * the same nonce and key.
548 *
549 * There are two common strategies for managing nonces with CTR:
550 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200551 * 1. You can handle everything as a single message processed over
552 * successive calls to this function. In that case, you want to
553 * set \p nonce_counter and \p nc_off to 0 for the first call, and
554 * then preserve the values of \p nonce_counter, \p nc_off and \p
555 * stream_block across calls to this function as they will be
556 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100557 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200558 * With this strategy, you must not encrypt more than 2**128
559 * blocks of data with the same key.
560 *
561 * 2. You can encrypt separate messages by dividing the \p
562 * nonce_counter buffer in two areas: the first one used for a
563 * per-message nonce, handled by yourself, and the second one
564 * updated by this function internally.
565 *
566 * For example, you might reserve the first 12 bytes for the
567 * per-message nonce, and the last 4 bytes for internal use. In that
568 * case, before calling this function on a new message you need to
569 * set the first 12 bytes of \p nonce_counter to your chosen nonce
570 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
571 * stream_block to be ignored). That way, you can encrypt at most
572 * 2**96 messages of up to 2**32 blocks each with the same key.
573 *
574 * The per-message nonce (or information sufficient to reconstruct
575 * it) needs to be communicated with the ciphertext and must be unique.
576 * The recommended way to ensure uniqueness is to use a message
577 * counter. An alternative is to generate random nonces, but this
578 * limits the number of messages that can be securely encrypted:
579 * for example, with 96-bit random nonces, you should not encrypt
580 * more than 2**32 messages with the same key.
581 *
582 * Note that for both stategies, sizes are measured in blocks and
583 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000584 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200585 * \warning Upon return, \p stream_block contains sensitive data. Its
586 * content must not be written to insecure storage and should be
587 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000588 *
Rose Zadik7f441272018-01-22 11:48:23 +0000589 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100590 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000591 * \param length The length of the input data.
592 * \param nc_off The offset in the current \p stream_block, for
593 * resuming within the current cipher stream. The
594 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100595 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000596 * \param nonce_counter The 128-bit nonce and counter.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100597 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000598 * \param stream_block The saved stream block for resuming. This is
599 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100600 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000601 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100602 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000603 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100604 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000605 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100606 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000607 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000609 size_t length,
610 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000611 unsigned char nonce_counter[16],
612 unsigned char stream_block[16],
613 const unsigned char *input,
614 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200615#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200616
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200617/**
Rose Zadik7f441272018-01-22 11:48:23 +0000618 * \brief Internal AES block encryption function. This is only
619 * exposed to allow overriding it using
620 * \c MBEDTLS_AES_ENCRYPT_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 encryption.
623 * \param input The plaintext block.
624 * \param output The output (ciphertext) 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 */
Andres AGf5bf7182017-03-03 14:09:56 +0000628int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
629 const unsigned char input[16],
630 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200631
632/**
Rose Zadik7f441272018-01-22 11:48:23 +0000633 * \brief Internal AES block decryption function. This is only
634 * exposed to allow overriding it using see
635 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200636 *
Rose Zadik7f441272018-01-22 11:48:23 +0000637 * \param ctx The AES context to use for decryption.
638 * \param input The ciphertext block.
639 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000640 *
Rose Zadik7f441272018-01-22 11:48:23 +0000641 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200642 */
Andres AGf5bf7182017-03-03 14:09:56 +0000643int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
644 const unsigned char input[16],
645 unsigned char output[16] );
646
647#if !defined(MBEDTLS_DEPRECATED_REMOVED)
648#if defined(MBEDTLS_DEPRECATED_WARNING)
649#define MBEDTLS_DEPRECATED __attribute__((deprecated))
650#else
651#define MBEDTLS_DEPRECATED
652#endif
653/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100654 * \brief Deprecated internal AES block encryption function
655 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000656 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100657 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000658 *
Rose Zadik7f441272018-01-22 11:48:23 +0000659 * \param ctx The AES context to use for encryption.
660 * \param input Plaintext block.
661 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000662 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100663MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
664 const unsigned char input[16],
665 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000666
667/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100668 * \brief Deprecated internal AES block decryption function
669 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000670 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100671 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000672 *
Rose Zadik7f441272018-01-22 11:48:23 +0000673 * \param ctx The AES context to use for decryption.
674 * \param input Ciphertext block.
675 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000676 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100677MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
678 const unsigned char input[16],
679 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000680
681#undef MBEDTLS_DEPRECATED
682#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200683
Ron Eldorfa8f6352017-06-20 15:48:46 +0300684
685#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000686/**
Rose Zadik7f441272018-01-22 11:48:23 +0000687 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000688 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100689 * \return \c 0 on success.
690 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000691 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000693
Ron Eldorfa8f6352017-06-20 15:48:46 +0300694#endif /* MBEDTLS_SELF_TEST */
695
Paul Bakker5121ce52009-01-03 21:22:43 +0000696#ifdef __cplusplus
697}
698#endif
699
700#endif /* aes.h */