blob: 055107ad0ec14f97e32fb27b92d49b3a44cf922f [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file aes.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +01004 * \brief This file contains AES definitions and functions.
5 *
6 * The Advanced Encryption Standard (AES) specifies a FIPS-approved
Rose Zadik7f441272018-01-22 11:48:23 +00007 * cryptographic algorithm that can be used to protect electronic
8 * data.
9 *
10 * The AES algorithm is a symmetric block cipher that can
11 * encrypt and decrypt information. For more information, see
12 * <em>FIPS Publication 197: Advanced Encryption Standard</em> and
13 * <em>ISO/IEC 18033-2:2006: Information technology -- Security
14 * techniques -- Encryption algorithms -- Part 2: Asymmetric
15 * ciphers</em>.
Jaeden Amerof167deb2018-05-30 19:20:48 +010016 *
17 * The AES-XTS block mode is standardized by NIST SP 800-38E
18 * <https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38e.pdf>
19 * and described in detail by IEEE P1619
20 * <https://ieeexplore.ieee.org/servlet/opac?punumber=4375278>.
Darryl Greena40a1012018-01-05 15:33:17 +000021 */
Rose Zadik5ad7aea2018-03-26 12:00:09 +010022
Rose Zadik7f441272018-01-22 11:48:23 +000023/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020024 * SPDX-License-Identifier: Apache-2.0
25 *
26 * Licensed under the Apache License, Version 2.0 (the "License"); you may
27 * not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
34 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000037 *
Rose Zadik7f441272018-01-22 11:48:23 +000038 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000039 */
Rose Zadik7f441272018-01-22 11:48:23 +000040
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#ifndef MBEDTLS_AES_H
42#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000043
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020045#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020046#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020048#endif
Paul Bakker90995b52013-06-24 19:20:35 +020049
Rich Evans00ab4702015-02-06 13:43:58 +000050#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020051#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000052
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010053/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000054#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
55#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Andres Amaya Garciac5380642017-11-28 19:57:51 +000057/* Error codes in range 0x0020-0x0022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
59#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000060
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000061/* Error codes in range 0x0021-0x0025 */
62#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030063
64/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
Rose Zadik7f441272018-01-22 11:48:23 +000065#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030066
67/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010068#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000069
Andres AGf5bf7182017-03-03 14:09:56 +000070#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
71 !defined(inline) && !defined(__cplusplus)
72#define inline __inline
73#endif
74
Paul Bakker407a0da2013-06-27 14:29:21 +020075#ifdef __cplusplus
76extern "C" {
77#endif
78
Ron Eldorb2aacec2017-05-18 16:53:08 +030079#if !defined(MBEDTLS_AES_ALT)
80// Regular implementation
81//
82
Paul Bakker5121ce52009-01-03 21:22:43 +000083/**
Rose Zadik7f441272018-01-22 11:48:23 +000084 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000085 */
Dawid Drozd428cc522018-07-24 10:02:47 +020086typedef struct mbedtls_aes_context
Paul Bakker5121ce52009-01-03 21:22:43 +000087{
Rose Zadik7f441272018-01-22 11:48:23 +000088 int nr; /*!< The number of rounds. */
89 uint32_t *rk; /*!< AES round keys. */
Andrzej Kureke78775e2020-07-02 10:57:00 -040090 uint32_t frk[8]; /*!< Fake AES round keys. */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +030091#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
92 uint32_t buf[44]; /*!< Unaligned data buffer */
93#else /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Rose Zadik7f441272018-01-22 11:48:23 +000094 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
95 hold 32 extra Bytes, which can be used for
96 one of the following purposes:
97 <ul><li>Alignment if VIA padlock is
98 used.</li>
99 <li>Simplifying key expansion in the 256-bit
100 case by generating an extra round key.
101 </li></ul> */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300102#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Paul Bakker5121ce52009-01-03 21:22:43 +0000103}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000105
Jaeden Amero9366feb2018-05-29 18:55:17 +0100106#if defined(MBEDTLS_CIPHER_MODE_XTS)
107/**
108 * \brief The AES XTS context-type definition.
109 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200110typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100111{
112 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
113 encryption or decryption. */
114 mbedtls_aes_context tweak; /*!< The AES context used for tweak
115 computation. */
116} mbedtls_aes_xts_context;
117#endif /* MBEDTLS_CIPHER_MODE_XTS */
118
Ron Eldorb2aacec2017-05-18 16:53:08 +0300119#else /* MBEDTLS_AES_ALT */
120#include "aes_alt.h"
121#endif /* MBEDTLS_AES_ALT */
122
Paul Bakker5121ce52009-01-03 21:22:43 +0000123/**
Rose Zadik7f441272018-01-22 11:48:23 +0000124 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200125 *
Rose Zadik7f441272018-01-22 11:48:23 +0000126 * It must be the first API called before using
127 * the context.
128 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100129 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200130 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200132
133/**
Rose Zadik7f441272018-01-22 11:48:23 +0000134 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200135 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100136 * \param ctx The AES context to clear.
137 * If this is \c NULL, this function does nothing.
138 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200141
Jaeden Amero9366feb2018-05-29 18:55:17 +0100142#if defined(MBEDTLS_CIPHER_MODE_XTS)
143/**
144 * \brief This function initializes the specified AES XTS context.
145 *
146 * It must be the first API called before using
147 * the context.
148 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100149 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100150 */
151void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
152
153/**
154 * \brief This function releases and clears the specified AES XTS context.
155 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100156 * \param ctx The AES XTS context to clear.
157 * If this is \c NULL, this function does nothing.
158 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100159 */
160void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
161#endif /* MBEDTLS_CIPHER_MODE_XTS */
162
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200163/**
Rose Zadik7f441272018-01-22 11:48:23 +0000164 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000165 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100166 * \param ctx The AES context to which the key should be bound.
167 * It must be initialized.
168 * \param key The encryption key.
169 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000170 * \param keybits The size of data passed in bits. Valid options are:
171 * <ul><li>128 bits</li>
172 * <li>192 bits</li>
173 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000174 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100175 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200176 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
177 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000178 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200180 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000181
182/**
Rose Zadik7f441272018-01-22 11:48:23 +0000183 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000184 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100185 * \param ctx The AES context to which the key should be bound.
186 * It must be initialized.
187 * \param key The decryption key.
188 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000189 * \param keybits The size of data passed. Valid options are:
190 * <ul><li>128 bits</li>
191 * <li>192 bits</li>
192 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000193 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100194 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200195 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
196 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000197 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200199 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000200
Jaeden Amero9366feb2018-05-29 18:55:17 +0100201#if defined(MBEDTLS_CIPHER_MODE_XTS)
202/**
203 * \brief This function prepares an XTS context for encryption and
204 * sets the encryption key.
205 *
206 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100207 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100208 * \param key The encryption key. This is comprised of the XTS key1
209 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100210 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100211 * \param keybits The size of \p key passed in bits. Valid options are:
212 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
213 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
214 *
215 * \return \c 0 on success.
216 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
217 */
218int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
219 const unsigned char *key,
220 unsigned int keybits );
221
222/**
223 * \brief This function prepares an XTS context for decryption and
224 * sets the decryption key.
225 *
226 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100227 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100228 * \param key The decryption key. This is comprised of the XTS key1
229 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100230 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100231 * \param keybits The size of \p key passed in bits. Valid options are:
232 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
233 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
234 *
235 * \return \c 0 on success.
236 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
237 */
238int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
239 const unsigned char *key,
240 unsigned int keybits );
241#endif /* MBEDTLS_CIPHER_MODE_XTS */
242
Paul Bakker5121ce52009-01-03 21:22:43 +0000243/**
Rose Zadik7f441272018-01-22 11:48:23 +0000244 * \brief This function performs an AES single-block encryption or
245 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000246 *
Rose Zadik7f441272018-01-22 11:48:23 +0000247 * It performs the operation defined in the \p mode parameter
248 * (encrypt or decrypt), on the input data buffer defined in
249 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000250 *
Rose Zadik7f441272018-01-22 11:48:23 +0000251 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
252 * mbedtls_aes_setkey_dec() must be called before the first
253 * call to this API with the same context.
254 *
255 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100256 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000257 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
258 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100259 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100260 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100261 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100262 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000263
264 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000265 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000268 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000269 unsigned char output[16] );
270
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000272/**
Rose Zadik7f441272018-01-22 11:48:23 +0000273 * \brief This function performs an AES-CBC encryption or decryption operation
274 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000275 *
Rose Zadik7f441272018-01-22 11:48:23 +0000276 * It performs the operation defined in the \p mode
277 * parameter (encrypt/decrypt), on the input data buffer defined in
278 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000279 *
Rose Zadik7f441272018-01-22 11:48:23 +0000280 * It can be called as many times as needed, until all the input
281 * data is processed. mbedtls_aes_init(), and either
282 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
283 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000284 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100285 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100286 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000287 *
288 * \note Upon exit, the content of the IV is updated so that you can
289 * call the same function again on the next
290 * block(s) of data and get the same result as if it was
291 * encrypted in one call. This allows a "streaming" usage.
292 * If you need to retain the contents of the IV, you should
293 * either save it manually or use the cipher module instead.
294 *
295 *
296 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100297 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000298 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
299 * #MBEDTLS_AES_DECRYPT.
300 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100301 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000302 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100303 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000304 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100305 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000306 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100307 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000308 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100309 * \return \c 0 on success.
310 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000311 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000312 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000314 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000315 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000316 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000317 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000318 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000320
Aorimn5f778012016-06-09 23:22:58 +0200321#if defined(MBEDTLS_CIPHER_MODE_XTS)
322/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100323 * \brief This function performs an AES-XTS encryption or decryption
324 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200325 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100326 * AES-XTS encrypts or decrypts blocks based on their location as
327 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100328 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200329 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100330 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
331 * AES blocks. If the data unit is larger than this, this function
332 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
333 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100334 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100335 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100336 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
337 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100338 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100339 * length between 16 bytes and 2^24 bytes inclusive
340 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100341 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100342 * bytes in little-endian format. For disk encryption, this
343 * is typically the index of the block device sector that
344 * contains the data.
345 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100346 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100347 * input.
348 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100349 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100350 * output.
Aorimn5f778012016-06-09 23:22:58 +0200351 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100352 * \return \c 0 on success.
353 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100354 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100355 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200356 */
Jaeden Amero9366feb2018-05-29 18:55:17 +0100357int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
358 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100359 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100360 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100361 const unsigned char *input,
362 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200363#endif /* MBEDTLS_CIPHER_MODE_XTS */
364
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200365#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000366/**
Rose Zadik7f441272018-01-22 11:48:23 +0000367 * \brief This function performs an AES-CFB128 encryption or decryption
368 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000369 *
Rose Zadik7f441272018-01-22 11:48:23 +0000370 * It performs the operation defined in the \p mode
371 * parameter (encrypt or decrypt), on the input data buffer
372 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000373 *
Rose Zadik7f441272018-01-22 11:48:23 +0000374 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
375 * regardless of whether you are performing an encryption or decryption
376 * operation, that is, regardless of the \p mode parameter. This is
377 * because CFB mode uses the same key schedule for encryption and
378 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000379 *
Rose Zadik7f441272018-01-22 11:48:23 +0000380 * \note Upon exit, the content of the IV is updated so that you can
381 * call the same function again on the next
382 * block(s) of data and get the same result as if it was
383 * encrypted in one call. This allows a "streaming" usage.
384 * If you need to retain the contents of the
385 * IV, you must either save it manually or use the cipher
386 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000387 *
Rose Zadik7f441272018-01-22 11:48:23 +0000388 *
389 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100390 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000391 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
392 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100393 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000394 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100395 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000396 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100397 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000398 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100399 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000400 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100401 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000402 *
403 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000404 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000406 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000407 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000408 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000409 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000410 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000411 unsigned char *output );
412
Paul Bakker9a736322012-11-14 12:39:52 +0000413/**
Rose Zadik7f441272018-01-22 11:48:23 +0000414 * \brief This function performs an AES-CFB8 encryption or decryption
415 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100416 *
Rose Zadik7f441272018-01-22 11:48:23 +0000417 * It performs the operation defined in the \p mode
418 * parameter (encrypt/decrypt), on the input data buffer defined
419 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100420 *
Rose Zadik7f441272018-01-22 11:48:23 +0000421 * Due to the nature of CFB, you must use the same key schedule for
422 * both encryption and decryption operations. Therefore, you must
423 * use the context initialized with mbedtls_aes_setkey_enc() for
424 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000425 *
Rose Zadik7f441272018-01-22 11:48:23 +0000426 * \note Upon exit, the content of the IV is updated so that you can
427 * call the same function again on the next
428 * block(s) of data and get the same result as if it was
429 * encrypted in one call. This allows a "streaming" usage.
430 * If you need to retain the contents of the
431 * IV, you should either save it manually or use the cipher
432 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100433 *
Rose Zadik7f441272018-01-22 11:48:23 +0000434 *
435 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100436 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000437 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
438 * #MBEDTLS_AES_DECRYPT
439 * \param length The length of the input data.
440 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100441 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000442 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100443 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000444 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100445 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000446 *
447 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100448 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200449int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100450 int mode,
451 size_t length,
452 unsigned char iv[16],
453 const unsigned char *input,
454 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200455#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100456
Simon Butcher76a5b222018-04-22 22:57:27 +0100457#if defined(MBEDTLS_CIPHER_MODE_OFB)
458/**
Simon Butcher5db13622018-06-04 22:11:25 +0100459 * \brief This function performs an AES-OFB (Output Feedback Mode)
460 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100461 *
Simon Butcher5db13622018-06-04 22:11:25 +0100462 * For OFB, you must set up the context with
463 * mbedtls_aes_setkey_enc(), regardless of whether you are
464 * performing an encryption or decryption operation. This is
465 * because OFB mode uses the same key schedule for encryption and
466 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100467 *
Simon Butcher5db13622018-06-04 22:11:25 +0100468 * The OFB operation is identical for encryption or decryption,
469 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100470 *
Simon Butcher5db13622018-06-04 22:11:25 +0100471 * \note Upon exit, the content of iv, the Initialisation Vector, is
472 * updated so that you can call the same function again on the next
473 * block(s) of data and get the same result as if it was encrypted
474 * in one call. This allows a "streaming" usage, by initialising
475 * iv_off to 0 before the first call, and preserving its value
476 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100477 *
Simon Butcher5db13622018-06-04 22:11:25 +0100478 * For non-streaming use, the iv should be initialised on each call
479 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100480 *
Simon Butcher5db13622018-06-04 22:11:25 +0100481 * If you need to retain the contents of the initialisation vector,
482 * you must either save it manually or use the cipher module
483 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100484 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100485 * \warning For the OFB mode, the initialisation vector must be unique
486 * every encryption operation. Reuse of an initialisation vector
487 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100488 *
489 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100490 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100491 * \param length The length of the input data.
492 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100493 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100494 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100495 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100496 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100497 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100498 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100499 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100500 *
501 * \return \c 0 on success.
502 */
503int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
504 size_t length,
505 size_t *iv_off,
506 unsigned char iv[16],
507 const unsigned char *input,
508 unsigned char *output );
509
510#endif /* MBEDTLS_CIPHER_MODE_OFB */
511
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200512#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100513/**
Rose Zadik7f441272018-01-22 11:48:23 +0000514 * \brief This function performs an AES-CTR encryption or decryption
515 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000516 *
Rose Zadik7f441272018-01-22 11:48:23 +0000517 * This function performs the operation defined in the \p mode
518 * parameter (encrypt/decrypt), on the input data buffer
519 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000520 *
Rose Zadik7f441272018-01-22 11:48:23 +0000521 * Due to the nature of CTR, you must use the same key schedule
522 * for both encryption and decryption operations. Therefore, you
523 * must use the context initialized with mbedtls_aes_setkey_enc()
524 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000525 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100526 * \warning You must never reuse a nonce value with the same key. Doing so
527 * would void the encryption for the two messages encrypted with
528 * the same nonce and key.
529 *
530 * There are two common strategies for managing nonces with CTR:
531 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200532 * 1. You can handle everything as a single message processed over
533 * successive calls to this function. In that case, you want to
534 * set \p nonce_counter and \p nc_off to 0 for the first call, and
535 * then preserve the values of \p nonce_counter, \p nc_off and \p
536 * stream_block across calls to this function as they will be
537 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100538 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200539 * With this strategy, you must not encrypt more than 2**128
540 * blocks of data with the same key.
541 *
542 * 2. You can encrypt separate messages by dividing the \p
543 * nonce_counter buffer in two areas: the first one used for a
544 * per-message nonce, handled by yourself, and the second one
545 * updated by this function internally.
546 *
547 * For example, you might reserve the first 12 bytes for the
548 * per-message nonce, and the last 4 bytes for internal use. In that
549 * case, before calling this function on a new message you need to
550 * set the first 12 bytes of \p nonce_counter to your chosen nonce
551 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
552 * stream_block to be ignored). That way, you can encrypt at most
553 * 2**96 messages of up to 2**32 blocks each with the same key.
554 *
555 * The per-message nonce (or information sufficient to reconstruct
556 * it) needs to be communicated with the ciphertext and must be unique.
557 * The recommended way to ensure uniqueness is to use a message
558 * counter. An alternative is to generate random nonces, but this
559 * limits the number of messages that can be securely encrypted:
560 * for example, with 96-bit random nonces, you should not encrypt
561 * more than 2**32 messages with the same key.
562 *
563 * Note that for both stategies, sizes are measured in blocks and
564 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000565 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200566 * \warning Upon return, \p stream_block contains sensitive data. Its
567 * content must not be written to insecure storage and should be
568 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000569 *
Rose Zadik7f441272018-01-22 11:48:23 +0000570 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100571 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000572 * \param length The length of the input data.
573 * \param nc_off The offset in the current \p stream_block, for
574 * resuming within the current cipher stream. The
575 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100576 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000577 * \param nonce_counter The 128-bit nonce and counter.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100578 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000579 * \param stream_block The saved stream block for resuming. This is
580 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100581 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000582 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100583 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000584 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100585 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000586 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100587 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000588 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200589int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000590 size_t length,
591 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000592 unsigned char nonce_counter[16],
593 unsigned char stream_block[16],
594 const unsigned char *input,
595 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200597
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200598/**
Rose Zadik7f441272018-01-22 11:48:23 +0000599 * \brief Internal AES block encryption function. This is only
600 * exposed to allow overriding it using
601 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200602 *
Rose Zadik7f441272018-01-22 11:48:23 +0000603 * \param ctx The AES context to use for encryption.
604 * \param input The plaintext block.
605 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000606 *
Rose Zadik7f441272018-01-22 11:48:23 +0000607 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200608 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200609 */
Andres AGf5bf7182017-03-03 14:09:56 +0000610int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
611 const unsigned char input[16],
612 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200613
614/**
Rose Zadik7f441272018-01-22 11:48:23 +0000615 * \brief Internal AES block decryption function. This is only
616 * exposed to allow overriding it using see
617 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200618 *
Rose Zadik7f441272018-01-22 11:48:23 +0000619 * \param ctx The AES context to use for decryption.
620 * \param input The ciphertext block.
621 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000622 *
Rose Zadik7f441272018-01-22 11:48:23 +0000623 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200624 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200625 */
Andres AGf5bf7182017-03-03 14:09:56 +0000626int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
627 const unsigned char input[16],
628 unsigned char output[16] );
629
630#if !defined(MBEDTLS_DEPRECATED_REMOVED)
631#if defined(MBEDTLS_DEPRECATED_WARNING)
632#define MBEDTLS_DEPRECATED __attribute__((deprecated))
633#else
634#define MBEDTLS_DEPRECATED
635#endif
636/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100637 * \brief Deprecated internal AES block encryption function
638 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000639 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100640 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000641 *
Rose Zadik7f441272018-01-22 11:48:23 +0000642 * \param ctx The AES context to use for encryption.
643 * \param input Plaintext block.
644 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000645 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100646MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
647 const unsigned char input[16],
648 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000649
650/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100651 * \brief Deprecated internal AES block decryption function
652 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000653 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100654 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000655 *
Rose Zadik7f441272018-01-22 11:48:23 +0000656 * \param ctx The AES context to use for decryption.
657 * \param input Ciphertext block.
658 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000659 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100660MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
661 const unsigned char input[16],
662 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000663
664#undef MBEDTLS_DEPRECATED
665#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200666
Ron Eldorfa8f6352017-06-20 15:48:46 +0300667
668#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000669/**
Rose Zadik7f441272018-01-22 11:48:23 +0000670 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000671 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100672 * \return \c 0 on success.
673 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000674 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000676
Ron Eldorfa8f6352017-06-20 15:48:46 +0300677#endif /* MBEDTLS_SELF_TEST */
678
Paul Bakker5121ce52009-01-03 21:22:43 +0000679#ifdef __cplusplus
680}
681#endif
682
683#endif /* aes.h */