blob: d20cdbd6da86530e68f5d67b420918fdc8ba6dca [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/*
24 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
25 * 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 * **********
65 *
Rose Zadik7f441272018-01-22 11:48:23 +000066 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000067 */
Rose Zadik7f441272018-01-22 11:48:23 +000068
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#ifndef MBEDTLS_AES_H
70#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020073#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020074#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020076#endif
Paul Bakker90995b52013-06-24 19:20:35 +020077
Rich Evans00ab4702015-02-06 13:43:58 +000078#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020079#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000080
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010081/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000082#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
83#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000084
Andres Amaya Garciac5380642017-11-28 19:57:51 +000085/* Error codes in range 0x0020-0x0022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
87#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000088
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000089/* Error codes in range 0x0021-0x0025 */
90#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030091
92/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Rose Zadik7f441272018-01-22 11:48:23 +000093#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030094
95/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010096#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000097
Andres AGf5bf7182017-03-03 14:09:56 +000098#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
99 !defined(inline) && !defined(__cplusplus)
100#define inline __inline
101#endif
102
Paul Bakker407a0da2013-06-27 14:29:21 +0200103#ifdef __cplusplus
104extern "C" {
105#endif
106
Ron Eldorb2aacec2017-05-18 16:53:08 +0300107#if !defined(MBEDTLS_AES_ALT)
108// Regular implementation
109//
110
Paul Bakker5121ce52009-01-03 21:22:43 +0000111/**
Rose Zadik7f441272018-01-22 11:48:23 +0000112 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +0000113 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200114typedef struct mbedtls_aes_context
Paul Bakker5121ce52009-01-03 21:22:43 +0000115{
Rose Zadik7f441272018-01-22 11:48:23 +0000116 int nr; /*!< The number of rounds. */
117 uint32_t *rk; /*!< AES round keys. */
118 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
119 hold 32 extra Bytes, which can be used for
120 one of the following purposes:
121 <ul><li>Alignment if VIA padlock is
122 used.</li>
123 <li>Simplifying key expansion in the 256-bit
124 case by generating an extra round key.
125 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +0000126}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000128
Jaeden Amero9366feb2018-05-29 18:55:17 +0100129#if defined(MBEDTLS_CIPHER_MODE_XTS)
130/**
131 * \brief The AES XTS context-type definition.
132 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200133typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100134{
135 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
136 encryption or decryption. */
137 mbedtls_aes_context tweak; /*!< The AES context used for tweak
138 computation. */
139} mbedtls_aes_xts_context;
140#endif /* MBEDTLS_CIPHER_MODE_XTS */
141
Ron Eldorb2aacec2017-05-18 16:53:08 +0300142#else /* MBEDTLS_AES_ALT */
143#include "aes_alt.h"
144#endif /* MBEDTLS_AES_ALT */
145
Paul Bakker5121ce52009-01-03 21:22:43 +0000146/**
Rose Zadik7f441272018-01-22 11:48:23 +0000147 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200148 *
Rose Zadik7f441272018-01-22 11:48:23 +0000149 * It must be the first API called before using
150 * the context.
151 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100152 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200153 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200155
156/**
Rose Zadik7f441272018-01-22 11:48:23 +0000157 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200158 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100159 * \param ctx The AES context to clear.
160 * If this is \c NULL, this function does nothing.
161 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200162 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200164
Jaeden Amero9366feb2018-05-29 18:55:17 +0100165#if defined(MBEDTLS_CIPHER_MODE_XTS)
166/**
167 * \brief This function initializes the specified AES XTS context.
168 *
169 * It must be the first API called before using
170 * the context.
171 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100172 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100173 */
174void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
175
176/**
177 * \brief This function releases and clears the specified AES XTS context.
178 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100179 * \param ctx The AES XTS context to clear.
180 * If this is \c NULL, this function does nothing.
181 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100182 */
183void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
184#endif /* MBEDTLS_CIPHER_MODE_XTS */
185
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200186/**
Rose Zadik7f441272018-01-22 11:48:23 +0000187 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000188 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100189 * \param ctx The AES context to which the key should be bound.
190 * It must be initialized.
191 * \param key The encryption key.
192 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000193 * \param keybits The size of data passed in bits. Valid options are:
194 * <ul><li>128 bits</li>
195 * <li>192 bits</li>
196 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000197 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100198 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100199 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000200 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200202 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000203
204/**
Rose Zadik7f441272018-01-22 11:48:23 +0000205 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100207 * \param ctx The AES context to which the key should be bound.
208 * It must be initialized.
209 * \param key The decryption key.
210 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000211 * \param keybits The size of data passed. Valid options are:
212 * <ul><li>128 bits</li>
213 * <li>192 bits</li>
214 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000215 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100216 * \return \c 0 on success.
217 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000218 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200220 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000221
Jaeden Amero9366feb2018-05-29 18:55:17 +0100222#if defined(MBEDTLS_CIPHER_MODE_XTS)
223/**
224 * \brief This function prepares an XTS context for encryption and
225 * sets the encryption key.
226 *
227 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100228 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100229 * \param key The encryption key. This is comprised of the XTS key1
230 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100231 * 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 */
239int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
240 const unsigned char *key,
241 unsigned int keybits );
242
243/**
244 * \brief This function prepares an XTS context for decryption and
245 * sets the decryption key.
246 *
247 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100248 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100249 * \param key The decryption key. This is comprised of the XTS key1
250 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100251 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100252 * \param keybits The size of \p key passed in bits. Valid options are:
253 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
254 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
255 *
256 * \return \c 0 on success.
257 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
258 */
259int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
260 const unsigned char *key,
261 unsigned int keybits );
262#endif /* MBEDTLS_CIPHER_MODE_XTS */
263
Paul Bakker5121ce52009-01-03 21:22:43 +0000264/**
Rose Zadik7f441272018-01-22 11:48:23 +0000265 * \brief This function performs an AES single-block encryption or
266 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 *
Rose Zadik7f441272018-01-22 11:48:23 +0000268 * It performs the operation defined in the \p mode parameter
269 * (encrypt or decrypt), on the input data buffer defined in
270 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000271 *
Rose Zadik7f441272018-01-22 11:48:23 +0000272 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
273 * mbedtls_aes_setkey_dec() must be called before the first
274 * call to this API with the same context.
275 *
276 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100277 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000278 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
279 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100280 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100281 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100282 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100283 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000284
285 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000286 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200287int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000288 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000289 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000290 unsigned char output[16] );
291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000293/**
Rose Zadik7f441272018-01-22 11:48:23 +0000294 * \brief This function performs an AES-CBC encryption or decryption operation
295 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000296 *
Rose Zadik7f441272018-01-22 11:48:23 +0000297 * It performs the operation defined in the \p mode
298 * parameter (encrypt/decrypt), on the input data buffer defined in
299 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000300 *
Rose Zadik7f441272018-01-22 11:48:23 +0000301 * It can be called as many times as needed, until all the input
302 * data is processed. mbedtls_aes_init(), and either
303 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
304 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000305 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100306 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100307 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000308 *
309 * \note Upon exit, the content of the IV is updated so that you can
310 * call the same function again on the next
311 * block(s) of data and get the same result as if it was
312 * encrypted in one call. This allows a "streaming" usage.
313 * If you need to retain the contents of the IV, you should
314 * either save it manually or use the cipher module instead.
315 *
316 *
317 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100318 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000319 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
320 * #MBEDTLS_AES_DECRYPT.
321 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100322 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000323 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100324 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000325 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100326 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000327 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100328 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000329 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100330 * \return \c 0 on success.
331 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000332 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000333 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000335 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000336 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000337 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000338 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000339 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000341
Aorimn5f778012016-06-09 23:22:58 +0200342#if defined(MBEDTLS_CIPHER_MODE_XTS)
343/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100344 * \brief This function performs an AES-XTS encryption or decryption
345 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200346 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100347 * AES-XTS encrypts or decrypts blocks based on their location as
348 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100349 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200350 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100351 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
352 * AES blocks. If the data unit is larger than this, this function
353 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
354 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100355 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100356 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100357 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
358 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100359 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100360 * length between 16 bytes and 2^24 bytes inclusive
361 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100362 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100363 * bytes in little-endian format. For disk encryption, this
364 * is typically the index of the block device sector that
365 * contains the data.
366 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100367 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100368 * input.
369 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100370 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100371 * output.
Aorimn5f778012016-06-09 23:22:58 +0200372 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100373 * \return \c 0 on success.
374 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100375 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100376 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200377 */
Jaeden Amero9366feb2018-05-29 18:55:17 +0100378int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
379 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100380 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100381 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100382 const unsigned char *input,
383 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200384#endif /* MBEDTLS_CIPHER_MODE_XTS */
385
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200386#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000387/**
Rose Zadik7f441272018-01-22 11:48:23 +0000388 * \brief This function performs an AES-CFB128 encryption or decryption
389 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000390 *
Rose Zadik7f441272018-01-22 11:48:23 +0000391 * It performs the operation defined in the \p mode
392 * parameter (encrypt or decrypt), on the input data buffer
393 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000394 *
Rose Zadik7f441272018-01-22 11:48:23 +0000395 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
396 * regardless of whether you are performing an encryption or decryption
397 * operation, that is, regardless of the \p mode parameter. This is
398 * because CFB mode uses the same key schedule for encryption and
399 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000400 *
Rose Zadik7f441272018-01-22 11:48:23 +0000401 * \note Upon exit, the content of the IV is updated so that you can
402 * call the same function again on the next
403 * block(s) of data and get the same result as if it was
404 * encrypted in one call. This allows a "streaming" usage.
405 * If you need to retain the contents of the
406 * IV, you must either save it manually or use the cipher
407 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000408 *
Rose Zadik7f441272018-01-22 11:48:23 +0000409 *
410 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100411 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000412 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
413 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100414 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000415 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100416 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000417 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100418 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000419 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100420 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000421 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100422 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000423 *
424 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000425 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000427 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000428 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000429 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000430 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000431 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000432 unsigned char *output );
433
Paul Bakker9a736322012-11-14 12:39:52 +0000434/**
Rose Zadik7f441272018-01-22 11:48:23 +0000435 * \brief This function performs an AES-CFB8 encryption or decryption
436 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100437 *
Rose Zadik7f441272018-01-22 11:48:23 +0000438 * It performs the operation defined in the \p mode
439 * parameter (encrypt/decrypt), on the input data buffer defined
440 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100441 *
Rose Zadik7f441272018-01-22 11:48:23 +0000442 * Due to the nature of CFB, you must use the same key schedule for
443 * both encryption and decryption operations. Therefore, you must
444 * use the context initialized with mbedtls_aes_setkey_enc() for
445 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000446 *
Rose Zadik7f441272018-01-22 11:48:23 +0000447 * \note Upon exit, the content of the IV is updated so that you can
448 * call the same function again on the next
449 * block(s) of data and get the same result as if it was
450 * encrypted in one call. This allows a "streaming" usage.
451 * If you need to retain the contents of the
452 * IV, you should either save it manually or use the cipher
453 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100454 *
Rose Zadik7f441272018-01-22 11:48:23 +0000455 *
456 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100457 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000458 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
459 * #MBEDTLS_AES_DECRYPT
460 * \param length The length of the input data.
461 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100462 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000463 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100464 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000465 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100466 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000467 *
468 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100469 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200470int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100471 int mode,
472 size_t length,
473 unsigned char iv[16],
474 const unsigned char *input,
475 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100477
Simon Butcher76a5b222018-04-22 22:57:27 +0100478#if defined(MBEDTLS_CIPHER_MODE_OFB)
479/**
Simon Butcher5db13622018-06-04 22:11:25 +0100480 * \brief This function performs an AES-OFB (Output Feedback Mode)
481 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100482 *
Simon Butcher5db13622018-06-04 22:11:25 +0100483 * For OFB, you must set up the context with
484 * mbedtls_aes_setkey_enc(), regardless of whether you are
485 * performing an encryption or decryption operation. This is
486 * because OFB mode uses the same key schedule for encryption and
487 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100488 *
Simon Butcher5db13622018-06-04 22:11:25 +0100489 * The OFB operation is identical for encryption or decryption,
490 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100491 *
Simon Butcher5db13622018-06-04 22:11:25 +0100492 * \note Upon exit, the content of iv, the Initialisation Vector, is
493 * updated so that you can call the same function again on the next
494 * block(s) of data and get the same result as if it was encrypted
495 * in one call. This allows a "streaming" usage, by initialising
496 * iv_off to 0 before the first call, and preserving its value
497 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100498 *
Simon Butcher5db13622018-06-04 22:11:25 +0100499 * For non-streaming use, the iv should be initialised on each call
500 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100501 *
Simon Butcher5db13622018-06-04 22:11:25 +0100502 * If you need to retain the contents of the initialisation vector,
503 * you must either save it manually or use the cipher module
504 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100505 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100506 * \warning For the OFB mode, the initialisation vector must be unique
507 * every encryption operation. Reuse of an initialisation vector
508 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100509 *
510 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100511 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100512 * \param length The length of the input data.
513 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100514 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100515 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100516 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100517 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100518 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100519 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100520 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100521 *
522 * \return \c 0 on success.
523 */
524int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
525 size_t length,
526 size_t *iv_off,
527 unsigned char iv[16],
528 const unsigned char *input,
529 unsigned char *output );
530
531#endif /* MBEDTLS_CIPHER_MODE_OFB */
532
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200533#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100534/**
Rose Zadik7f441272018-01-22 11:48:23 +0000535 * \brief This function performs an AES-CTR encryption or decryption
536 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000537 *
Rose Zadik7f441272018-01-22 11:48:23 +0000538 * This function performs the operation defined in the \p mode
539 * parameter (encrypt/decrypt), on the input data buffer
540 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000541 *
Rose Zadik7f441272018-01-22 11:48:23 +0000542 * Due to the nature of CTR, you must use the same key schedule
543 * for both encryption and decryption operations. Therefore, you
544 * must use the context initialized with mbedtls_aes_setkey_enc()
545 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000546 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100547 * \warning You must never reuse a nonce value with the same key. Doing so
548 * would void the encryption for the two messages encrypted with
549 * the same nonce and key.
550 *
551 * There are two common strategies for managing nonces with CTR:
552 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200553 * 1. You can handle everything as a single message processed over
554 * successive calls to this function. In that case, you want to
555 * set \p nonce_counter and \p nc_off to 0 for the first call, and
556 * then preserve the values of \p nonce_counter, \p nc_off and \p
557 * stream_block across calls to this function as they will be
558 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100559 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200560 * With this strategy, you must not encrypt more than 2**128
561 * blocks of data with the same key.
562 *
563 * 2. You can encrypt separate messages by dividing the \p
564 * nonce_counter buffer in two areas: the first one used for a
565 * per-message nonce, handled by yourself, and the second one
566 * updated by this function internally.
567 *
568 * For example, you might reserve the first 12 bytes for the
569 * per-message nonce, and the last 4 bytes for internal use. In that
570 * case, before calling this function on a new message you need to
571 * set the first 12 bytes of \p nonce_counter to your chosen nonce
572 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
573 * stream_block to be ignored). That way, you can encrypt at most
574 * 2**96 messages of up to 2**32 blocks each with the same key.
575 *
576 * The per-message nonce (or information sufficient to reconstruct
577 * it) needs to be communicated with the ciphertext and must be unique.
578 * The recommended way to ensure uniqueness is to use a message
579 * counter. An alternative is to generate random nonces, but this
580 * limits the number of messages that can be securely encrypted:
581 * for example, with 96-bit random nonces, you should not encrypt
582 * more than 2**32 messages with the same key.
583 *
584 * Note that for both stategies, sizes are measured in blocks and
585 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000586 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200587 * \warning Upon return, \p stream_block contains sensitive data. Its
588 * content must not be written to insecure storage and should be
589 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000590 *
Rose Zadik7f441272018-01-22 11:48:23 +0000591 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100592 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000593 * \param length The length of the input data.
594 * \param nc_off The offset in the current \p stream_block, for
595 * resuming within the current cipher stream. The
596 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100597 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000598 * \param nonce_counter The 128-bit nonce and counter.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100599 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000600 * \param stream_block The saved stream block for resuming. This is
601 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100602 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000603 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100604 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000605 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100606 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000607 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100608 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000609 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000611 size_t length,
612 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000613 unsigned char nonce_counter[16],
614 unsigned char stream_block[16],
615 const unsigned char *input,
616 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200617#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200618
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200619/**
Rose Zadik7f441272018-01-22 11:48:23 +0000620 * \brief Internal AES block encryption function. This is only
621 * exposed to allow overriding it using
622 * \c MBEDTLS_AES_ENCRYPT_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 encryption.
625 * \param input The plaintext block.
626 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000627 *
Rose Zadik7f441272018-01-22 11:48:23 +0000628 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200629 */
Andres AGf5bf7182017-03-03 14:09:56 +0000630int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
631 const unsigned char input[16],
632 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200633
634/**
Rose Zadik7f441272018-01-22 11:48:23 +0000635 * \brief Internal AES block decryption function. This is only
636 * exposed to allow overriding it using see
637 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200638 *
Rose Zadik7f441272018-01-22 11:48:23 +0000639 * \param ctx The AES context to use for decryption.
640 * \param input The ciphertext block.
641 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000642 *
Rose Zadik7f441272018-01-22 11:48:23 +0000643 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200644 */
Andres AGf5bf7182017-03-03 14:09:56 +0000645int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
646 const unsigned char input[16],
647 unsigned char output[16] );
648
649#if !defined(MBEDTLS_DEPRECATED_REMOVED)
650#if defined(MBEDTLS_DEPRECATED_WARNING)
651#define MBEDTLS_DEPRECATED __attribute__((deprecated))
652#else
653#define MBEDTLS_DEPRECATED
654#endif
655/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100656 * \brief Deprecated internal AES block encryption 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_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000660 *
Rose Zadik7f441272018-01-22 11:48:23 +0000661 * \param ctx The AES context to use for encryption.
662 * \param input Plaintext block.
663 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000664 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100665MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
666 const unsigned char input[16],
667 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000668
669/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100670 * \brief Deprecated internal AES block decryption function
671 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000672 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100673 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000674 *
Rose Zadik7f441272018-01-22 11:48:23 +0000675 * \param ctx The AES context to use for decryption.
676 * \param input Ciphertext block.
677 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000678 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100679MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
680 const unsigned char input[16],
681 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000682
683#undef MBEDTLS_DEPRECATED
684#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200685
Ron Eldorfa8f6352017-06-20 15:48:46 +0300686
687#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000688/**
Rose Zadik7f441272018-01-22 11:48:23 +0000689 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000690 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100691 * \return \c 0 on success.
692 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000693 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200694int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000695
Ron Eldorfa8f6352017-06-20 15:48:46 +0300696#endif /* MBEDTLS_SELF_TEST */
697
Paul Bakker5121ce52009-01-03 21:22:43 +0000698#ifdef __cplusplus
699}
700#endif
701
702#endif /* aes.h */