blob: 6990be0ee700a2687366fd66acb377011df5432a [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. */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +030090#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
91 uint32_t buf[44]; /*!< Unaligned data buffer */
92#else /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Rose Zadik7f441272018-01-22 11:48:23 +000093 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
94 hold 32 extra Bytes, which can be used for
95 one of the following purposes:
96 <ul><li>Alignment if VIA padlock is
97 used.</li>
98 <li>Simplifying key expansion in the 256-bit
99 case by generating an extra round key.
100 </li></ul> */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300101#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Paul Bakker5121ce52009-01-03 21:22:43 +0000102}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
Jaeden Amero9366feb2018-05-29 18:55:17 +0100105#if defined(MBEDTLS_CIPHER_MODE_XTS)
106/**
107 * \brief The AES XTS context-type definition.
108 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200109typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100110{
111 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
112 encryption or decryption. */
113 mbedtls_aes_context tweak; /*!< The AES context used for tweak
114 computation. */
115} mbedtls_aes_xts_context;
116#endif /* MBEDTLS_CIPHER_MODE_XTS */
117
Ron Eldorb2aacec2017-05-18 16:53:08 +0300118#else /* MBEDTLS_AES_ALT */
119#include "aes_alt.h"
120#endif /* MBEDTLS_AES_ALT */
121
Paul Bakker5121ce52009-01-03 21:22:43 +0000122/**
Rose Zadik7f441272018-01-22 11:48:23 +0000123 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200124 *
Rose Zadik7f441272018-01-22 11:48:23 +0000125 * It must be the first API called before using
126 * the context.
127 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100128 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200129 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200131
132/**
Rose Zadik7f441272018-01-22 11:48:23 +0000133 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200134 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100135 * \param ctx The AES context to clear.
136 * If this is \c NULL, this function does nothing.
137 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200138 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200140
Jaeden Amero9366feb2018-05-29 18:55:17 +0100141#if defined(MBEDTLS_CIPHER_MODE_XTS)
142/**
143 * \brief This function initializes the specified AES XTS context.
144 *
145 * It must be the first API called before using
146 * the context.
147 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100148 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100149 */
150void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
151
152/**
153 * \brief This function releases and clears the specified AES XTS context.
154 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100155 * \param ctx The AES XTS context to clear.
156 * If this is \c NULL, this function does nothing.
157 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100158 */
159void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
160#endif /* MBEDTLS_CIPHER_MODE_XTS */
161
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200162/**
Rose Zadik7f441272018-01-22 11:48:23 +0000163 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000164 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100165 * \param ctx The AES context to which the key should be bound.
166 * It must be initialized.
167 * \param key The encryption key.
168 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000169 * \param keybits The size of data passed in bits. Valid options are:
170 * <ul><li>128 bits</li>
171 * <li>192 bits</li>
172 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000173 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100174 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200175 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
176 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000177 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200178int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200179 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000180
181/**
Rose Zadik7f441272018-01-22 11:48:23 +0000182 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000183 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100184 * \param ctx The AES context to which the key should be bound.
185 * It must be initialized.
186 * \param key The decryption key.
187 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000188 * \param keybits The size of data passed. Valid options are:
189 * <ul><li>128 bits</li>
190 * <li>192 bits</li>
191 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000192 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100193 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200194 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
195 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000196 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200198 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000199
Jaeden Amero9366feb2018-05-29 18:55:17 +0100200#if defined(MBEDTLS_CIPHER_MODE_XTS)
201/**
202 * \brief This function prepares an XTS context for encryption and
203 * sets the encryption key.
204 *
205 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100206 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100207 * \param key The encryption key. This is comprised of the XTS key1
208 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100209 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100210 * \param keybits The size of \p key passed in bits. Valid options are:
211 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
212 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
213 *
214 * \return \c 0 on success.
215 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
216 */
217int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
218 const unsigned char *key,
219 unsigned int keybits );
220
221/**
222 * \brief This function prepares an XTS context for decryption and
223 * sets the decryption key.
224 *
225 * \param ctx The AES XTS context to which the key should be bound.
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 decryption 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_dec( mbedtls_aes_xts_context *ctx,
238 const unsigned char *key,
239 unsigned int keybits );
240#endif /* MBEDTLS_CIPHER_MODE_XTS */
241
Paul Bakker5121ce52009-01-03 21:22:43 +0000242/**
Rose Zadik7f441272018-01-22 11:48:23 +0000243 * \brief This function performs an AES single-block encryption or
244 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 *
Rose Zadik7f441272018-01-22 11:48:23 +0000246 * It performs the operation defined in the \p mode parameter
247 * (encrypt or decrypt), on the input data buffer defined in
248 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000249 *
Rose Zadik7f441272018-01-22 11:48:23 +0000250 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
251 * mbedtls_aes_setkey_dec() must be called before the first
252 * call to this API with the same context.
253 *
254 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100255 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000256 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
257 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100258 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100259 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100260 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100261 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000262
263 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000264 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200265int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000266 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000267 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000268 unsigned char output[16] );
269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000271/**
Rose Zadik7f441272018-01-22 11:48:23 +0000272 * \brief This function performs an AES-CBC encryption or decryption operation
273 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000274 *
Rose Zadik7f441272018-01-22 11:48:23 +0000275 * It performs the operation defined in the \p mode
276 * parameter (encrypt/decrypt), on the input data buffer defined in
277 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000278 *
Rose Zadik7f441272018-01-22 11:48:23 +0000279 * It can be called as many times as needed, until all the input
280 * data is processed. mbedtls_aes_init(), and either
281 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
282 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000283 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100284 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100285 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000286 *
287 * \note Upon exit, the content of the IV is updated so that you can
288 * call the same function again on the next
289 * block(s) of data and get the same result as if it was
290 * encrypted in one call. This allows a "streaming" usage.
291 * If you need to retain the contents of the IV, you should
292 * either save it manually or use the cipher module instead.
293 *
294 *
295 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100296 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000297 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
298 * #MBEDTLS_AES_DECRYPT.
299 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100300 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000301 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100302 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000303 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100304 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000305 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100306 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000307 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100308 * \return \c 0 on success.
309 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000310 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000311 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000313 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000314 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000315 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000316 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000317 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000319
Aorimn5f778012016-06-09 23:22:58 +0200320#if defined(MBEDTLS_CIPHER_MODE_XTS)
321/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100322 * \brief This function performs an AES-XTS encryption or decryption
323 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200324 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100325 * AES-XTS encrypts or decrypts blocks based on their location as
326 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100327 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200328 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100329 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
330 * AES blocks. If the data unit is larger than this, this function
331 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
332 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100333 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100334 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100335 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
336 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100337 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100338 * length between 16 bytes and 2^24 bytes inclusive
339 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100340 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100341 * bytes in little-endian format. For disk encryption, this
342 * is typically the index of the block device sector that
343 * contains the data.
344 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100345 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100346 * input.
347 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100348 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100349 * output.
Aorimn5f778012016-06-09 23:22:58 +0200350 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100351 * \return \c 0 on success.
352 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100353 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100354 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200355 */
Jaeden Amero9366feb2018-05-29 18:55:17 +0100356int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
357 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100358 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100359 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100360 const unsigned char *input,
361 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200362#endif /* MBEDTLS_CIPHER_MODE_XTS */
363
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200364#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000365/**
Rose Zadik7f441272018-01-22 11:48:23 +0000366 * \brief This function performs an AES-CFB128 encryption or decryption
367 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000368 *
Rose Zadik7f441272018-01-22 11:48:23 +0000369 * It performs the operation defined in the \p mode
370 * parameter (encrypt or decrypt), on the input data buffer
371 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000372 *
Rose Zadik7f441272018-01-22 11:48:23 +0000373 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
374 * regardless of whether you are performing an encryption or decryption
375 * operation, that is, regardless of the \p mode parameter. This is
376 * because CFB mode uses the same key schedule for encryption and
377 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000378 *
Rose Zadik7f441272018-01-22 11:48:23 +0000379 * \note Upon exit, the content of the IV is updated so that you can
380 * call the same function again on the next
381 * block(s) of data and get the same result as if it was
382 * encrypted in one call. This allows a "streaming" usage.
383 * If you need to retain the contents of the
384 * IV, you must either save it manually or use the cipher
385 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000386 *
Rose Zadik7f441272018-01-22 11:48:23 +0000387 *
388 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100389 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000390 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
391 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100392 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000393 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100394 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000395 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100396 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000397 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100398 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000399 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100400 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000401 *
402 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000403 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200404int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000405 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000406 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000407 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000408 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000409 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000410 unsigned char *output );
411
Paul Bakker9a736322012-11-14 12:39:52 +0000412/**
Rose Zadik7f441272018-01-22 11:48:23 +0000413 * \brief This function performs an AES-CFB8 encryption or decryption
414 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100415 *
Rose Zadik7f441272018-01-22 11:48:23 +0000416 * It performs the operation defined in the \p mode
417 * parameter (encrypt/decrypt), on the input data buffer defined
418 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100419 *
Rose Zadik7f441272018-01-22 11:48:23 +0000420 * Due to the nature of CFB, you must use the same key schedule for
421 * both encryption and decryption operations. Therefore, you must
422 * use the context initialized with mbedtls_aes_setkey_enc() for
423 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000424 *
Rose Zadik7f441272018-01-22 11:48:23 +0000425 * \note Upon exit, the content of the IV is updated so that you can
426 * call the same function again on the next
427 * block(s) of data and get the same result as if it was
428 * encrypted in one call. This allows a "streaming" usage.
429 * If you need to retain the contents of the
430 * IV, you should either save it manually or use the cipher
431 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100432 *
Rose Zadik7f441272018-01-22 11:48:23 +0000433 *
434 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100435 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000436 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
437 * #MBEDTLS_AES_DECRYPT
438 * \param length The length of the input data.
439 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100440 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000441 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100442 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000443 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100444 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000445 *
446 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100447 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200448int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100449 int mode,
450 size_t length,
451 unsigned char iv[16],
452 const unsigned char *input,
453 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200454#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100455
Simon Butcher76a5b222018-04-22 22:57:27 +0100456#if defined(MBEDTLS_CIPHER_MODE_OFB)
457/**
Simon Butcher5db13622018-06-04 22:11:25 +0100458 * \brief This function performs an AES-OFB (Output Feedback Mode)
459 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100460 *
Simon Butcher5db13622018-06-04 22:11:25 +0100461 * For OFB, you must set up the context with
462 * mbedtls_aes_setkey_enc(), regardless of whether you are
463 * performing an encryption or decryption operation. This is
464 * because OFB mode uses the same key schedule for encryption and
465 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100466 *
Simon Butcher5db13622018-06-04 22:11:25 +0100467 * The OFB operation is identical for encryption or decryption,
468 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100469 *
Simon Butcher5db13622018-06-04 22:11:25 +0100470 * \note Upon exit, the content of iv, the Initialisation Vector, is
471 * updated so that you can call the same function again on the next
472 * block(s) of data and get the same result as if it was encrypted
473 * in one call. This allows a "streaming" usage, by initialising
474 * iv_off to 0 before the first call, and preserving its value
475 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100476 *
Simon Butcher5db13622018-06-04 22:11:25 +0100477 * For non-streaming use, the iv should be initialised on each call
478 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100479 *
Simon Butcher5db13622018-06-04 22:11:25 +0100480 * If you need to retain the contents of the initialisation vector,
481 * you must either save it manually or use the cipher module
482 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100483 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100484 * \warning For the OFB mode, the initialisation vector must be unique
485 * every encryption operation. Reuse of an initialisation vector
486 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100487 *
488 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100489 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100490 * \param length The length of the input data.
491 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100492 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100493 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100494 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100495 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100496 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100497 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100498 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100499 *
500 * \return \c 0 on success.
501 */
502int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
503 size_t length,
504 size_t *iv_off,
505 unsigned char iv[16],
506 const unsigned char *input,
507 unsigned char *output );
508
509#endif /* MBEDTLS_CIPHER_MODE_OFB */
510
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200511#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100512/**
Rose Zadik7f441272018-01-22 11:48:23 +0000513 * \brief This function performs an AES-CTR encryption or decryption
514 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000515 *
Rose Zadik7f441272018-01-22 11:48:23 +0000516 * This function performs the operation defined in the \p mode
517 * parameter (encrypt/decrypt), on the input data buffer
518 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000519 *
Rose Zadik7f441272018-01-22 11:48:23 +0000520 * Due to the nature of CTR, you must use the same key schedule
521 * for both encryption and decryption operations. Therefore, you
522 * must use the context initialized with mbedtls_aes_setkey_enc()
523 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000524 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100525 * \warning You must never reuse a nonce value with the same key. Doing so
526 * would void the encryption for the two messages encrypted with
527 * the same nonce and key.
528 *
529 * There are two common strategies for managing nonces with CTR:
530 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200531 * 1. You can handle everything as a single message processed over
532 * successive calls to this function. In that case, you want to
533 * set \p nonce_counter and \p nc_off to 0 for the first call, and
534 * then preserve the values of \p nonce_counter, \p nc_off and \p
535 * stream_block across calls to this function as they will be
536 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100537 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200538 * With this strategy, you must not encrypt more than 2**128
539 * blocks of data with the same key.
540 *
541 * 2. You can encrypt separate messages by dividing the \p
542 * nonce_counter buffer in two areas: the first one used for a
543 * per-message nonce, handled by yourself, and the second one
544 * updated by this function internally.
545 *
546 * For example, you might reserve the first 12 bytes for the
547 * per-message nonce, and the last 4 bytes for internal use. In that
548 * case, before calling this function on a new message you need to
549 * set the first 12 bytes of \p nonce_counter to your chosen nonce
550 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
551 * stream_block to be ignored). That way, you can encrypt at most
552 * 2**96 messages of up to 2**32 blocks each with the same key.
553 *
554 * The per-message nonce (or information sufficient to reconstruct
555 * it) needs to be communicated with the ciphertext and must be unique.
556 * The recommended way to ensure uniqueness is to use a message
557 * counter. An alternative is to generate random nonces, but this
558 * limits the number of messages that can be securely encrypted:
559 * for example, with 96-bit random nonces, you should not encrypt
560 * more than 2**32 messages with the same key.
561 *
562 * Note that for both stategies, sizes are measured in blocks and
563 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000564 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200565 * \warning Upon return, \p stream_block contains sensitive data. Its
566 * content must not be written to insecure storage and should be
567 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000568 *
Rose Zadik7f441272018-01-22 11:48:23 +0000569 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100570 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000571 * \param length The length of the input data.
572 * \param nc_off The offset in the current \p stream_block, for
573 * resuming within the current cipher stream. The
574 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100575 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000576 * \param nonce_counter The 128-bit nonce and counter.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100577 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000578 * \param stream_block The saved stream block for resuming. This is
579 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100580 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000581 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100582 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000583 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100584 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000585 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100586 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000587 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200588int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000589 size_t length,
590 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000591 unsigned char nonce_counter[16],
592 unsigned char stream_block[16],
593 const unsigned char *input,
594 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200596
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200597/**
Rose Zadik7f441272018-01-22 11:48:23 +0000598 * \brief Internal AES block encryption function. This is only
599 * exposed to allow overriding it using
600 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200601 *
Rose Zadik7f441272018-01-22 11:48:23 +0000602 * \param ctx The AES context to use for encryption.
603 * \param input The plaintext block.
604 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000605 *
Rose Zadik7f441272018-01-22 11:48:23 +0000606 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200607 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200608 */
Andres AGf5bf7182017-03-03 14:09:56 +0000609int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
610 const unsigned char input[16],
611 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200612
613/**
Rose Zadik7f441272018-01-22 11:48:23 +0000614 * \brief Internal AES block decryption function. This is only
615 * exposed to allow overriding it using see
616 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200617 *
Rose Zadik7f441272018-01-22 11:48:23 +0000618 * \param ctx The AES context to use for decryption.
619 * \param input The ciphertext block.
620 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000621 *
Rose Zadik7f441272018-01-22 11:48:23 +0000622 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200623 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200624 */
Andres AGf5bf7182017-03-03 14:09:56 +0000625int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
626 const unsigned char input[16],
627 unsigned char output[16] );
628
629#if !defined(MBEDTLS_DEPRECATED_REMOVED)
630#if defined(MBEDTLS_DEPRECATED_WARNING)
631#define MBEDTLS_DEPRECATED __attribute__((deprecated))
632#else
633#define MBEDTLS_DEPRECATED
634#endif
635/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100636 * \brief Deprecated internal AES block encryption function
637 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000638 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100639 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000640 *
Rose Zadik7f441272018-01-22 11:48:23 +0000641 * \param ctx The AES context to use for encryption.
642 * \param input Plaintext block.
643 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000644 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100645MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
646 const unsigned char input[16],
647 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000648
649/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100650 * \brief Deprecated internal AES block decryption function
651 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000652 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100653 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000654 *
Rose Zadik7f441272018-01-22 11:48:23 +0000655 * \param ctx The AES context to use for decryption.
656 * \param input Ciphertext block.
657 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000658 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100659MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
660 const unsigned char input[16],
661 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000662
663#undef MBEDTLS_DEPRECATED
664#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200665
Ron Eldorfa8f6352017-06-20 15:48:46 +0300666
667#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000668/**
Rose Zadik7f441272018-01-22 11:48:23 +0000669 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000670 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100671 * \return \c 0 on success.
672 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000673 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000675
Ron Eldorfa8f6352017-06-20 15:48:46 +0300676#endif /* MBEDTLS_SELF_TEST */
677
Paul Bakker5121ce52009-01-03 21:22:43 +0000678#ifdef __cplusplus
679}
680#endif
681
682#endif /* aes.h */