blob: 18c50bb9ce27f4237006c7c3b24551019c3237fb [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 */
Shelly Libermanc907c812020-11-17 11:33:25 +020086
87//#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
88#define AES_128_EXPANDED_KEY_SIZE_IN_WORDS 44
89//#endif
Dawid Drozd428cc522018-07-24 10:02:47 +020090typedef struct mbedtls_aes_context
Paul Bakker5121ce52009-01-03 21:22:43 +000091{
Rose Zadik7f441272018-01-22 11:48:23 +000092 int nr; /*!< The number of rounds. */
93 uint32_t *rk; /*!< AES round keys. */
Andrzej Kurekfac2f9b2020-07-19 00:32:34 -040094#if defined(MBEDTLS_AES_SCA_COUNTERMEASURES)
Andrzej Kureke78775e2020-07-02 10:57:00 -040095 uint32_t frk[8]; /*!< Fake AES round keys. */
Andrzej Kurekfac2f9b2020-07-19 00:32:34 -040096#endif
Andrzej Kurekfba59212020-08-07 21:02:25 -040097#if defined(MBEDTLS_VALIDATE_AES_KEYS_INTEGRITY)
Andrzej Kurek9539f832020-08-10 15:58:13 -040098 uint32_t hash; /*!< hash of the set key */
Andrzej Kurekfba59212020-08-07 21:02:25 -040099#endif
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300100#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
Shelly Libermanc907c812020-11-17 11:33:25 +0200101 uint32_t buf[AES_128_EXPANDED_KEY_SIZE_IN_WORDS]; /*!< Unaligned data buffer for expanded key only */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300102#else /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Rose Zadik7f441272018-01-22 11:48:23 +0000103 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
104 hold 32 extra Bytes, which can be used for
105 one of the following purposes:
106 <ul><li>Alignment if VIA padlock is
107 used.</li>
108 <li>Simplifying key expansion in the 256-bit
109 case by generating an extra round key.
110 </li></ul> */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300111#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Paul Bakker5121ce52009-01-03 21:22:43 +0000112}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000114
Jaeden Amero9366feb2018-05-29 18:55:17 +0100115#if defined(MBEDTLS_CIPHER_MODE_XTS)
116/**
117 * \brief The AES XTS context-type definition.
118 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200119typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100120{
121 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
122 encryption or decryption. */
123 mbedtls_aes_context tweak; /*!< The AES context used for tweak
124 computation. */
125} mbedtls_aes_xts_context;
126#endif /* MBEDTLS_CIPHER_MODE_XTS */
127
Ron Eldorb2aacec2017-05-18 16:53:08 +0300128#else /* MBEDTLS_AES_ALT */
129#include "aes_alt.h"
130#endif /* MBEDTLS_AES_ALT */
131
Paul Bakker5121ce52009-01-03 21:22:43 +0000132/**
Rose Zadik7f441272018-01-22 11:48:23 +0000133 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200134 *
Rose Zadik7f441272018-01-22 11:48:23 +0000135 * It must be the first API called before using
136 * the context.
137 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100138 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200141
142/**
Rose Zadik7f441272018-01-22 11:48:23 +0000143 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200144 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100145 * \param ctx The AES context to clear.
146 * If this is \c NULL, this function does nothing.
147 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200148 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200150
Jaeden Amero9366feb2018-05-29 18:55:17 +0100151#if defined(MBEDTLS_CIPHER_MODE_XTS)
152/**
153 * \brief This function initializes the specified AES XTS context.
154 *
155 * It must be the first API called before using
156 * the context.
157 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100158 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100159 */
160void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
161
162/**
163 * \brief This function releases and clears the specified AES XTS context.
164 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100165 * \param ctx The AES XTS context to clear.
166 * If this is \c NULL, this function does nothing.
167 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100168 */
169void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
170#endif /* MBEDTLS_CIPHER_MODE_XTS */
171
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200172/**
Rose Zadik7f441272018-01-22 11:48:23 +0000173 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000174 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100175 * \param ctx The AES context to which the key should be bound.
176 * It must be initialized.
177 * \param key The encryption key.
178 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000179 * \param keybits The size of data passed in bits. Valid options are:
180 * <ul><li>128 bits</li>
181 * <li>192 bits</li>
182 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000183 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100184 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200185 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
186 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000187 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200189 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000190
191/**
Rose Zadik7f441272018-01-22 11:48:23 +0000192 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000193 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100194 * \param ctx The AES context to which the key should be bound.
195 * It must be initialized.
196 * \param key The decryption key.
197 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000198 * \param keybits The size of data passed. Valid options are:
199 * <ul><li>128 bits</li>
200 * <li>192 bits</li>
201 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000202 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100203 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200204 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
205 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200208 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000209
Jaeden Amero9366feb2018-05-29 18:55:17 +0100210#if defined(MBEDTLS_CIPHER_MODE_XTS)
211/**
212 * \brief This function prepares an XTS context for encryption and
213 * sets the encryption key.
214 *
215 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100216 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100217 * \param key The encryption key. This is comprised of the XTS key1
218 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100219 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100220 * \param keybits The size of \p key passed in bits. Valid options are:
221 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
222 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
223 *
224 * \return \c 0 on success.
225 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
226 */
227int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
228 const unsigned char *key,
229 unsigned int keybits );
230
231/**
232 * \brief This function prepares an XTS context for decryption and
233 * sets the decryption key.
234 *
235 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100236 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100237 * \param key The decryption key. This is comprised of the XTS key1
238 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100239 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100240 * \param keybits The size of \p key passed in bits. Valid options are:
241 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
242 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
243 *
244 * \return \c 0 on success.
245 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
246 */
247int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
248 const unsigned char *key,
249 unsigned int keybits );
250#endif /* MBEDTLS_CIPHER_MODE_XTS */
251
Paul Bakker5121ce52009-01-03 21:22:43 +0000252/**
Rose Zadik7f441272018-01-22 11:48:23 +0000253 * \brief This function performs an AES single-block encryption or
254 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000255 *
Rose Zadik7f441272018-01-22 11:48:23 +0000256 * It performs the operation defined in the \p mode parameter
257 * (encrypt or decrypt), on the input data buffer defined in
258 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000259 *
Rose Zadik7f441272018-01-22 11:48:23 +0000260 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
261 * mbedtls_aes_setkey_dec() must be called before the first
262 * call to this API with the same context.
263 *
264 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100265 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000266 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
267 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100268 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100269 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100270 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100271 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000272
273 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000274 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200275int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000276 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000277 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000278 unsigned char output[16] );
279
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000281/**
Rose Zadik7f441272018-01-22 11:48:23 +0000282 * \brief This function performs an AES-CBC encryption or decryption operation
283 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000284 *
Rose Zadik7f441272018-01-22 11:48:23 +0000285 * It performs the operation defined in the \p mode
286 * parameter (encrypt/decrypt), on the input data buffer defined in
287 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000288 *
Rose Zadik7f441272018-01-22 11:48:23 +0000289 * It can be called as many times as needed, until all the input
290 * data is processed. mbedtls_aes_init(), and either
291 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
292 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000293 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100294 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100295 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000296 *
297 * \note Upon exit, the content of the IV is updated so that you can
298 * call the same function again on the next
299 * block(s) of data and get the same result as if it was
300 * encrypted in one call. This allows a "streaming" usage.
301 * If you need to retain the contents of the IV, you should
302 * either save it manually or use the cipher module instead.
303 *
304 *
305 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100306 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000307 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
308 * #MBEDTLS_AES_DECRYPT.
309 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100310 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000311 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100312 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000313 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100314 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000315 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100316 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000317 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100318 * \return \c 0 on success.
319 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000320 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000321 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000323 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000324 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000325 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000326 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000327 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000329
Aorimn5f778012016-06-09 23:22:58 +0200330#if defined(MBEDTLS_CIPHER_MODE_XTS)
331/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100332 * \brief This function performs an AES-XTS encryption or decryption
333 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200334 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100335 * AES-XTS encrypts or decrypts blocks based on their location as
336 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100337 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200338 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100339 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
340 * AES blocks. If the data unit is larger than this, this function
341 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
342 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100343 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100344 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100345 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
346 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100347 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100348 * length between 16 bytes and 2^24 bytes inclusive
349 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100350 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100351 * bytes in little-endian format. For disk encryption, this
352 * is typically the index of the block device sector that
353 * contains the data.
354 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100355 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100356 * input.
357 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100358 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100359 * output.
Aorimn5f778012016-06-09 23:22:58 +0200360 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100361 * \return \c 0 on success.
362 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100363 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100364 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200365 */
Jaeden Amero9366feb2018-05-29 18:55:17 +0100366int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
367 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100368 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100369 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100370 const unsigned char *input,
371 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200372#endif /* MBEDTLS_CIPHER_MODE_XTS */
373
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200374#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000375/**
Rose Zadik7f441272018-01-22 11:48:23 +0000376 * \brief This function performs an AES-CFB128 encryption or decryption
377 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000378 *
Rose Zadik7f441272018-01-22 11:48:23 +0000379 * It performs the operation defined in the \p mode
380 * parameter (encrypt or decrypt), on the input data buffer
381 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000382 *
Rose Zadik7f441272018-01-22 11:48:23 +0000383 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
384 * regardless of whether you are performing an encryption or decryption
385 * operation, that is, regardless of the \p mode parameter. This is
386 * because CFB mode uses the same key schedule for encryption and
387 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000388 *
Rose Zadik7f441272018-01-22 11:48:23 +0000389 * \note Upon exit, the content of the IV is updated so that you can
390 * call the same function again on the next
391 * block(s) of data and get the same result as if it was
392 * encrypted in one call. This allows a "streaming" usage.
393 * If you need to retain the contents of the
394 * IV, you must either save it manually or use the cipher
395 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000396 *
Rose Zadik7f441272018-01-22 11:48:23 +0000397 *
398 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100399 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000400 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
401 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100402 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000403 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100404 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000405 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100406 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000407 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100408 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000409 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100410 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000411 *
412 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000413 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200414int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000415 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000416 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000417 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000418 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000419 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000420 unsigned char *output );
421
Paul Bakker9a736322012-11-14 12:39:52 +0000422/**
Rose Zadik7f441272018-01-22 11:48:23 +0000423 * \brief This function performs an AES-CFB8 encryption or decryption
424 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100425 *
Rose Zadik7f441272018-01-22 11:48:23 +0000426 * It performs the operation defined in the \p mode
427 * parameter (encrypt/decrypt), on the input data buffer defined
428 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100429 *
Rose Zadik7f441272018-01-22 11:48:23 +0000430 * Due to the nature of CFB, you must use the same key schedule for
431 * both encryption and decryption operations. Therefore, you must
432 * use the context initialized with mbedtls_aes_setkey_enc() for
433 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000434 *
Rose Zadik7f441272018-01-22 11:48:23 +0000435 * \note Upon exit, the content of the IV is updated so that you can
436 * call the same function again on the next
437 * block(s) of data and get the same result as if it was
438 * encrypted in one call. This allows a "streaming" usage.
439 * If you need to retain the contents of the
440 * IV, you should either save it manually or use the cipher
441 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100442 *
Rose Zadik7f441272018-01-22 11:48:23 +0000443 *
444 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100445 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000446 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
447 * #MBEDTLS_AES_DECRYPT
448 * \param length The length of the input data.
449 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100450 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000451 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100452 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000453 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100454 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000455 *
456 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100457 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200458int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100459 int mode,
460 size_t length,
461 unsigned char iv[16],
462 const unsigned char *input,
463 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200464#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100465
Simon Butcher76a5b222018-04-22 22:57:27 +0100466#if defined(MBEDTLS_CIPHER_MODE_OFB)
467/**
Simon Butcher5db13622018-06-04 22:11:25 +0100468 * \brief This function performs an AES-OFB (Output Feedback Mode)
469 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100470 *
Simon Butcher5db13622018-06-04 22:11:25 +0100471 * For OFB, you must set up the context with
472 * mbedtls_aes_setkey_enc(), regardless of whether you are
473 * performing an encryption or decryption operation. This is
474 * because OFB mode uses the same key schedule for encryption and
475 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100476 *
Simon Butcher5db13622018-06-04 22:11:25 +0100477 * The OFB operation is identical for encryption or decryption,
478 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100479 *
Simon Butcher5db13622018-06-04 22:11:25 +0100480 * \note Upon exit, the content of iv, the Initialisation Vector, is
481 * updated so that you can call the same function again on the next
482 * block(s) of data and get the same result as if it was encrypted
483 * in one call. This allows a "streaming" usage, by initialising
484 * iv_off to 0 before the first call, and preserving its value
485 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100486 *
Simon Butcher5db13622018-06-04 22:11:25 +0100487 * For non-streaming use, the iv should be initialised on each call
488 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100489 *
Simon Butcher5db13622018-06-04 22:11:25 +0100490 * If you need to retain the contents of the initialisation vector,
491 * you must either save it manually or use the cipher module
492 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100493 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100494 * \warning For the OFB mode, the initialisation vector must be unique
495 * every encryption operation. Reuse of an initialisation vector
496 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100497 *
498 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100499 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100500 * \param length The length of the input data.
501 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100502 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100503 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100504 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100505 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100506 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100507 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100508 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100509 *
510 * \return \c 0 on success.
511 */
512int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
513 size_t length,
514 size_t *iv_off,
515 unsigned char iv[16],
516 const unsigned char *input,
517 unsigned char *output );
518
519#endif /* MBEDTLS_CIPHER_MODE_OFB */
520
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100522/**
Rose Zadik7f441272018-01-22 11:48:23 +0000523 * \brief This function performs an AES-CTR encryption or decryption
524 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000525 *
Rose Zadik7f441272018-01-22 11:48:23 +0000526 * This function performs the operation defined in the \p mode
527 * parameter (encrypt/decrypt), on the input data buffer
528 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000529 *
Rose Zadik7f441272018-01-22 11:48:23 +0000530 * Due to the nature of CTR, you must use the same key schedule
531 * for both encryption and decryption operations. Therefore, you
532 * must use the context initialized with mbedtls_aes_setkey_enc()
533 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000534 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100535 * \warning You must never reuse a nonce value with the same key. Doing so
536 * would void the encryption for the two messages encrypted with
537 * the same nonce and key.
538 *
539 * There are two common strategies for managing nonces with CTR:
540 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200541 * 1. You can handle everything as a single message processed over
542 * successive calls to this function. In that case, you want to
543 * set \p nonce_counter and \p nc_off to 0 for the first call, and
544 * then preserve the values of \p nonce_counter, \p nc_off and \p
545 * stream_block across calls to this function as they will be
546 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100547 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200548 * With this strategy, you must not encrypt more than 2**128
549 * blocks of data with the same key.
550 *
551 * 2. You can encrypt separate messages by dividing the \p
552 * nonce_counter buffer in two areas: the first one used for a
553 * per-message nonce, handled by yourself, and the second one
554 * updated by this function internally.
555 *
556 * For example, you might reserve the first 12 bytes for the
557 * per-message nonce, and the last 4 bytes for internal use. In that
558 * case, before calling this function on a new message you need to
559 * set the first 12 bytes of \p nonce_counter to your chosen nonce
560 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
561 * stream_block to be ignored). That way, you can encrypt at most
562 * 2**96 messages of up to 2**32 blocks each with the same key.
563 *
564 * The per-message nonce (or information sufficient to reconstruct
565 * it) needs to be communicated with the ciphertext and must be unique.
566 * The recommended way to ensure uniqueness is to use a message
567 * counter. An alternative is to generate random nonces, but this
568 * limits the number of messages that can be securely encrypted:
569 * for example, with 96-bit random nonces, you should not encrypt
570 * more than 2**32 messages with the same key.
571 *
572 * Note that for both stategies, sizes are measured in blocks and
573 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000574 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200575 * \warning Upon return, \p stream_block contains sensitive data. Its
576 * content must not be written to insecure storage and should be
577 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000578 *
Rose Zadik7f441272018-01-22 11:48:23 +0000579 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100580 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000581 * \param length The length of the input data.
582 * \param nc_off The offset in the current \p stream_block, for
583 * resuming within the current cipher stream. The
584 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100585 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000586 * \param nonce_counter The 128-bit nonce and counter.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100587 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000588 * \param stream_block The saved stream block for resuming. This is
589 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100590 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000591 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100592 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000593 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100594 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000595 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100596 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000597 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000599 size_t length,
600 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000601 unsigned char nonce_counter[16],
602 unsigned char stream_block[16],
603 const unsigned char *input,
604 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200606
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200607/**
Rose Zadik7f441272018-01-22 11:48:23 +0000608 * \brief Internal AES block encryption function. This is only
609 * exposed to allow overriding it using
610 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200611 *
Rose Zadik7f441272018-01-22 11:48:23 +0000612 * \param ctx The AES context to use for encryption.
613 * \param input The plaintext block.
614 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000615 *
Rose Zadik7f441272018-01-22 11:48:23 +0000616 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200617 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200618 */
Andres AGf5bf7182017-03-03 14:09:56 +0000619int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
620 const unsigned char input[16],
621 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200622
623/**
Rose Zadik7f441272018-01-22 11:48:23 +0000624 * \brief Internal AES block decryption function. This is only
625 * exposed to allow overriding it using see
626 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200627 *
Rose Zadik7f441272018-01-22 11:48:23 +0000628 * \param ctx The AES context to use for decryption.
629 * \param input The ciphertext block.
630 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000631 *
Rose Zadik7f441272018-01-22 11:48:23 +0000632 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200633 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200634 */
Andres AGf5bf7182017-03-03 14:09:56 +0000635int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
636 const unsigned char input[16],
637 unsigned char output[16] );
638
639#if !defined(MBEDTLS_DEPRECATED_REMOVED)
640#if defined(MBEDTLS_DEPRECATED_WARNING)
641#define MBEDTLS_DEPRECATED __attribute__((deprecated))
642#else
643#define MBEDTLS_DEPRECATED
644#endif
645/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100646 * \brief Deprecated internal AES block encryption function
647 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000648 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100649 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000650 *
Rose Zadik7f441272018-01-22 11:48:23 +0000651 * \param ctx The AES context to use for encryption.
652 * \param input Plaintext block.
653 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000654 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100655MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
656 const unsigned char input[16],
657 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000658
659/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100660 * \brief Deprecated internal AES block decryption function
661 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000662 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100663 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000664 *
Rose Zadik7f441272018-01-22 11:48:23 +0000665 * \param ctx The AES context to use for decryption.
666 * \param input Ciphertext block.
667 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000668 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100669MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
670 const unsigned char input[16],
671 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000672
673#undef MBEDTLS_DEPRECATED
674#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200675
Ron Eldorfa8f6352017-06-20 15:48:46 +0300676
677#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000678/**
Rose Zadik7f441272018-01-22 11:48:23 +0000679 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000680 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100681 * \return \c 0 on success.
682 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000683 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200684int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000685
Ron Eldorfa8f6352017-06-20 15:48:46 +0300686#endif /* MBEDTLS_SELF_TEST */
687
Paul Bakker5121ce52009-01-03 21:22:43 +0000688#ifdef __cplusplus
689}
690#endif
691
692#endif /* aes.h */