blob: cb7d726aef05e6d7bc6b5abb4757b8291b5b2104 [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 Kurekfac2f9b2020-07-19 00:32:34 -040090#if defined(MBEDTLS_AES_SCA_COUNTERMEASURES)
Andrzej Kureke78775e2020-07-02 10:57:00 -040091 uint32_t frk[8]; /*!< Fake AES round keys. */
Andrzej Kurekfac2f9b2020-07-19 00:32:34 -040092#endif
Arto Kinnunen5ed870d2019-10-21 09:27:55 +030093#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
94 uint32_t buf[44]; /*!< Unaligned data buffer */
95#else /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Rose Zadik7f441272018-01-22 11:48:23 +000096 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
97 hold 32 extra Bytes, which can be used for
98 one of the following purposes:
99 <ul><li>Alignment if VIA padlock is
100 used.</li>
101 <li>Simplifying key expansion in the 256-bit
102 case by generating an extra round key.
103 </li></ul> */
Arto Kinnunen5ed870d2019-10-21 09:27:55 +0300104#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Paul Bakker5121ce52009-01-03 21:22:43 +0000105}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000107
Jaeden Amero9366feb2018-05-29 18:55:17 +0100108#if defined(MBEDTLS_CIPHER_MODE_XTS)
109/**
110 * \brief The AES XTS context-type definition.
111 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200112typedef struct mbedtls_aes_xts_context
Jaeden Amero9366feb2018-05-29 18:55:17 +0100113{
114 mbedtls_aes_context crypt; /*!< The AES context to use for AES block
115 encryption or decryption. */
116 mbedtls_aes_context tweak; /*!< The AES context used for tweak
117 computation. */
118} mbedtls_aes_xts_context;
119#endif /* MBEDTLS_CIPHER_MODE_XTS */
120
Ron Eldorb2aacec2017-05-18 16:53:08 +0300121#else /* MBEDTLS_AES_ALT */
122#include "aes_alt.h"
123#endif /* MBEDTLS_AES_ALT */
124
Paul Bakker5121ce52009-01-03 21:22:43 +0000125/**
Rose Zadik7f441272018-01-22 11:48:23 +0000126 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200127 *
Rose Zadik7f441272018-01-22 11:48:23 +0000128 * It must be the first API called before using
129 * the context.
130 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100131 * \param ctx The AES context to initialize. This must not be \c NULL.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200132 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200134
135/**
Rose Zadik7f441272018-01-22 11:48:23 +0000136 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200137 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100138 * \param ctx The AES context to clear.
139 * If this is \c NULL, this function does nothing.
140 * Otherwise, the context must have been at least initialized.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200141 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200143
Jaeden Amero9366feb2018-05-29 18:55:17 +0100144#if defined(MBEDTLS_CIPHER_MODE_XTS)
145/**
146 * \brief This function initializes the specified AES XTS context.
147 *
148 * It must be the first API called before using
149 * the context.
150 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100151 * \param ctx The AES XTS context to initialize. This must not be \c NULL.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100152 */
153void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
154
155/**
156 * \brief This function releases and clears the specified AES XTS context.
157 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100158 * \param ctx The AES XTS context to clear.
159 * If this is \c NULL, this function does nothing.
160 * Otherwise, the context must have been at least initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100161 */
162void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
163#endif /* MBEDTLS_CIPHER_MODE_XTS */
164
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200165/**
Rose Zadik7f441272018-01-22 11:48:23 +0000166 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000167 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100168 * \param ctx The AES context to which the key should be bound.
169 * It must be initialized.
170 * \param key The encryption key.
171 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000172 * \param keybits The size of data passed in bits. Valid options are:
173 * <ul><li>128 bits</li>
174 * <li>192 bits</li>
175 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000176 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100177 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200178 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
179 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000180 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200182 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000183
184/**
Rose Zadik7f441272018-01-22 11:48:23 +0000185 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000186 *
Manuel Pégourié-Gonnarded459e62018-12-12 10:20:33 +0100187 * \param ctx The AES context to which the key should be bound.
188 * It must be initialized.
189 * \param key The decryption key.
190 * This must be a readable buffer of size \p keybits bits.
Rose Zadik7f441272018-01-22 11:48:23 +0000191 * \param keybits The size of data passed. Valid options are:
192 * <ul><li>128 bits</li>
193 * <li>192 bits</li>
194 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000195 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100196 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200197 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH or
198 * #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000199 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200201 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000202
Jaeden Amero9366feb2018-05-29 18:55:17 +0100203#if defined(MBEDTLS_CIPHER_MODE_XTS)
204/**
205 * \brief This function prepares an XTS context for encryption and
206 * sets the encryption key.
207 *
208 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100209 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100210 * \param key The encryption key. This is comprised of the XTS key1
211 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100212 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100213 * \param keybits The size of \p key passed in bits. Valid options are:
214 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
215 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
216 *
217 * \return \c 0 on success.
218 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
219 */
220int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
221 const unsigned char *key,
222 unsigned int keybits );
223
224/**
225 * \brief This function prepares an XTS context for decryption and
226 * sets the decryption key.
227 *
228 * \param ctx The AES XTS context to which the key should be bound.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100229 * It must be initialized.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100230 * \param key The decryption key. This is comprised of the XTS key1
231 * concatenated with the XTS key2.
Manuel Pégourié-Gonnard68e3dff2018-12-12 12:48:04 +0100232 * This must be a readable buffer of size \p keybits bits.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100233 * \param keybits The size of \p key passed in bits. Valid options are:
234 * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
235 * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
236 *
237 * \return \c 0 on success.
238 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
239 */
240int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
241 const unsigned char *key,
242 unsigned int keybits );
243#endif /* MBEDTLS_CIPHER_MODE_XTS */
244
Paul Bakker5121ce52009-01-03 21:22:43 +0000245/**
Rose Zadik7f441272018-01-22 11:48:23 +0000246 * \brief This function performs an AES single-block encryption or
247 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 *
Rose Zadik7f441272018-01-22 11:48:23 +0000249 * It performs the operation defined in the \p mode parameter
250 * (encrypt or decrypt), on the input data buffer defined in
251 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000252 *
Rose Zadik7f441272018-01-22 11:48:23 +0000253 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
254 * mbedtls_aes_setkey_dec() must be called before the first
255 * call to this API with the same context.
256 *
257 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100258 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000259 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
260 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100261 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100262 * It must be readable and at least \c 16 Bytes long.
Manuel Pégourié-Gonnard1aca2602018-12-12 12:56:55 +0100263 * \param output The buffer where the output data will be written.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100264 * It must be writeable and at least \c 16 Bytes long.
Rose Zadik7f441272018-01-22 11:48:23 +0000265
266 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200268int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000269 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000270 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000271 unsigned char output[16] );
272
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000274/**
Rose Zadik7f441272018-01-22 11:48:23 +0000275 * \brief This function performs an AES-CBC encryption or decryption operation
276 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000277 *
Rose Zadik7f441272018-01-22 11:48:23 +0000278 * It performs the operation defined in the \p mode
279 * parameter (encrypt/decrypt), on the input data buffer defined in
280 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000281 *
Rose Zadik7f441272018-01-22 11:48:23 +0000282 * It can be called as many times as needed, until all the input
283 * data is processed. mbedtls_aes_init(), and either
284 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
285 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000286 *
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100287 * \note This function operates on full blocks, that is, the input size
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100288 * must be a multiple of the AES block size of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000289 *
290 * \note Upon exit, the content of the IV is updated so that you can
291 * call the same function again on the next
292 * block(s) of data and get the same result as if it was
293 * encrypted in one call. This allows a "streaming" usage.
294 * If you need to retain the contents of the IV, you should
295 * either save it manually or use the cipher module instead.
296 *
297 *
298 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard3178d1a2018-12-12 13:05:00 +0100299 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000300 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
301 * #MBEDTLS_AES_DECRYPT.
302 * \param length The length of the input data in Bytes. This must be a
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100303 * multiple of the block size (\c 16 Bytes).
Rose Zadik7f441272018-01-22 11:48:23 +0000304 * \param iv Initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100305 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000306 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100307 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000308 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100309 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000310 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100311 * \return \c 0 on success.
312 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000313 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000314 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000316 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000317 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000318 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000319 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000320 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000322
Aorimn5f778012016-06-09 23:22:58 +0200323#if defined(MBEDTLS_CIPHER_MODE_XTS)
324/**
Jaeden Amero9366feb2018-05-29 18:55:17 +0100325 * \brief This function performs an AES-XTS encryption or decryption
326 * operation for an entire XTS data unit.
Aorimn5f778012016-06-09 23:22:58 +0200327 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100328 * AES-XTS encrypts or decrypts blocks based on their location as
329 * defined by a data unit number. The data unit number must be
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100330 * provided by \p data_unit.
Aorimn5f778012016-06-09 23:22:58 +0200331 *
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100332 * NIST SP 800-38E limits the maximum size of a data unit to 2^20
333 * AES blocks. If the data unit is larger than this, this function
334 * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
335 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100336 * \param ctx The AES XTS context to use for AES XTS operations.
Manuel Pégourié-Gonnard191af132018-12-13 10:15:30 +0100337 * It must be initialized and bound to a key.
Jaeden Amero9366feb2018-05-29 18:55:17 +0100338 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
339 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100340 * \param length The length of a data unit in Bytes. This can be any
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100341 * length between 16 bytes and 2^24 bytes inclusive
342 * (between 1 and 2^20 block cipher blocks).
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100343 * \param data_unit The address of the data unit encoded as an array of 16
Jaeden Amero9366feb2018-05-29 18:55:17 +0100344 * bytes in little-endian format. For disk encryption, this
345 * is typically the index of the block device sector that
346 * contains the data.
347 * \param input The buffer holding the input data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100348 * data unit). This function reads \p length Bytes from \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100349 * input.
350 * \param output The buffer holding the output data (which is an entire
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100351 * data unit). This function writes \p length Bytes to \p
Jaeden Amero9366feb2018-05-29 18:55:17 +0100352 * output.
Aorimn5f778012016-06-09 23:22:58 +0200353 *
Jaeden Amero9366feb2018-05-29 18:55:17 +0100354 * \return \c 0 on success.
355 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100356 * smaller than an AES block in size (16 Bytes) or if \p
Jaeden Amero0a8b0202018-05-30 15:36:06 +0100357 * length is larger than 2^20 blocks (16 MiB).
Aorimn5f778012016-06-09 23:22:58 +0200358 */
Jaeden Amero9366feb2018-05-29 18:55:17 +0100359int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
360 int mode,
Jaeden Amero5162b932018-05-29 12:55:24 +0100361 size_t length,
Jaeden Amerocd9fc5e2018-05-30 15:23:24 +0100362 const unsigned char data_unit[16],
Jaeden Amero9366feb2018-05-29 18:55:17 +0100363 const unsigned char *input,
364 unsigned char *output );
Aorimn5f778012016-06-09 23:22:58 +0200365#endif /* MBEDTLS_CIPHER_MODE_XTS */
366
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000368/**
Rose Zadik7f441272018-01-22 11:48:23 +0000369 * \brief This function performs an AES-CFB128 encryption or decryption
370 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000371 *
Rose Zadik7f441272018-01-22 11:48:23 +0000372 * It performs the operation defined in the \p mode
373 * parameter (encrypt or decrypt), on the input data buffer
374 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000375 *
Rose Zadik7f441272018-01-22 11:48:23 +0000376 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
377 * regardless of whether you are performing an encryption or decryption
378 * operation, that is, regardless of the \p mode parameter. This is
379 * because CFB mode uses the same key schedule for encryption and
380 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000381 *
Rose Zadik7f441272018-01-22 11:48:23 +0000382 * \note Upon exit, the content of the IV is updated so that you can
383 * call the same function again on the next
384 * block(s) of data and get the same result as if it was
385 * encrypted in one call. This allows a "streaming" usage.
386 * If you need to retain the contents of the
387 * IV, you must either save it manually or use the cipher
388 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000389 *
Rose Zadik7f441272018-01-22 11:48:23 +0000390 *
391 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100392 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000393 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
394 * #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100395 * \param length The length of the input data in Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000396 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100397 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000398 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100399 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000400 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100401 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000402 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100403 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000404 *
405 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000406 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200407int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000408 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000409 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000410 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000411 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000412 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000413 unsigned char *output );
414
Paul Bakker9a736322012-11-14 12:39:52 +0000415/**
Rose Zadik7f441272018-01-22 11:48:23 +0000416 * \brief This function performs an AES-CFB8 encryption or decryption
417 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100418 *
Rose Zadik7f441272018-01-22 11:48:23 +0000419 * It performs the operation defined in the \p mode
420 * parameter (encrypt/decrypt), on the input data buffer defined
421 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100422 *
Rose Zadik7f441272018-01-22 11:48:23 +0000423 * Due to the nature of CFB, you must use the same key schedule for
424 * both encryption and decryption operations. Therefore, you must
425 * use the context initialized with mbedtls_aes_setkey_enc() for
426 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000427 *
Rose Zadik7f441272018-01-22 11:48:23 +0000428 * \note Upon exit, the content of the IV is updated so that you can
429 * call the same function again on the next
430 * block(s) of data and get the same result as if it was
431 * encrypted in one call. This allows a "streaming" usage.
432 * If you need to retain the contents of the
433 * IV, you should either save it manually or use the cipher
434 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100435 *
Rose Zadik7f441272018-01-22 11:48:23 +0000436 *
437 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard1677cca2018-12-13 10:27:13 +0100438 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000439 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
440 * #MBEDTLS_AES_DECRYPT
441 * \param length The length of the input data.
442 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100443 * It must be a readable and writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000444 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100445 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000446 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100447 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000448 *
449 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100450 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200451int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100452 int mode,
453 size_t length,
454 unsigned char iv[16],
455 const unsigned char *input,
456 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100458
Simon Butcher76a5b222018-04-22 22:57:27 +0100459#if defined(MBEDTLS_CIPHER_MODE_OFB)
460/**
Simon Butcher5db13622018-06-04 22:11:25 +0100461 * \brief This function performs an AES-OFB (Output Feedback Mode)
462 * encryption or decryption operation.
Simon Butcher76a5b222018-04-22 22:57:27 +0100463 *
Simon Butcher5db13622018-06-04 22:11:25 +0100464 * For OFB, you must set up the context with
465 * mbedtls_aes_setkey_enc(), regardless of whether you are
466 * performing an encryption or decryption operation. This is
467 * because OFB mode uses the same key schedule for encryption and
468 * decryption.
Simon Butcher76a5b222018-04-22 22:57:27 +0100469 *
Simon Butcher5db13622018-06-04 22:11:25 +0100470 * The OFB operation is identical for encryption or decryption,
471 * therefore no operation mode needs to be specified.
Simon Butcher76a5b222018-04-22 22:57:27 +0100472 *
Simon Butcher5db13622018-06-04 22:11:25 +0100473 * \note Upon exit, the content of iv, the Initialisation Vector, is
474 * updated so that you can call the same function again on the next
475 * block(s) of data and get the same result as if it was encrypted
476 * in one call. This allows a "streaming" usage, by initialising
477 * iv_off to 0 before the first call, and preserving its value
478 * between calls.
Simon Butcher968646c2018-06-02 18:27:04 +0100479 *
Simon Butcher5db13622018-06-04 22:11:25 +0100480 * For non-streaming use, the iv should be initialised on each call
481 * to a unique value, and iv_off set to 0 on each call.
Simon Butcher968646c2018-06-02 18:27:04 +0100482 *
Simon Butcher5db13622018-06-04 22:11:25 +0100483 * If you need to retain the contents of the initialisation vector,
484 * you must either save it manually or use the cipher module
485 * instead.
Simon Butcher968646c2018-06-02 18:27:04 +0100486 *
Jaeden Amerocb2c9352018-06-08 10:34:08 +0100487 * \warning For the OFB mode, the initialisation vector must be unique
488 * every encryption operation. Reuse of an initialisation vector
489 * will compromise security.
Simon Butcher76a5b222018-04-22 22:57:27 +0100490 *
491 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100492 * It must be initialized and bound to a key.
Simon Butcher76a5b222018-04-22 22:57:27 +0100493 * \param length The length of the input data.
494 * \param iv_off The offset in IV (updated after use).
Manuel Pégourié-Gonnard8e41eb72018-12-13 11:00:56 +0100495 * It must point to a valid \c size_t.
Simon Butcher76a5b222018-04-22 22:57:27 +0100496 * \param iv The initialization vector (updated after use).
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100497 * It must be a readable and writeable buffer of \c 16 Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100498 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100499 * It must be readable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100500 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100501 * It must be writeable and of size \p length Bytes.
Simon Butcher76a5b222018-04-22 22:57:27 +0100502 *
503 * \return \c 0 on success.
504 */
505int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
506 size_t length,
507 size_t *iv_off,
508 unsigned char iv[16],
509 const unsigned char *input,
510 unsigned char *output );
511
512#endif /* MBEDTLS_CIPHER_MODE_OFB */
513
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100515/**
Rose Zadik7f441272018-01-22 11:48:23 +0000516 * \brief This function performs an AES-CTR encryption or decryption
517 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000518 *
Rose Zadik7f441272018-01-22 11:48:23 +0000519 * This function performs the operation defined in the \p mode
520 * parameter (encrypt/decrypt), on the input data buffer
521 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000522 *
Rose Zadik7f441272018-01-22 11:48:23 +0000523 * Due to the nature of CTR, you must use the same key schedule
524 * for both encryption and decryption operations. Therefore, you
525 * must use the context initialized with mbedtls_aes_setkey_enc()
526 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000527 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100528 * \warning You must never reuse a nonce value with the same key. Doing so
529 * would void the encryption for the two messages encrypted with
530 * the same nonce and key.
531 *
532 * There are two common strategies for managing nonces with CTR:
533 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200534 * 1. You can handle everything as a single message processed over
535 * successive calls to this function. In that case, you want to
536 * set \p nonce_counter and \p nc_off to 0 for the first call, and
537 * then preserve the values of \p nonce_counter, \p nc_off and \p
538 * stream_block across calls to this function as they will be
539 * updated by this function.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100540 *
Manuel Pégourié-Gonnard4f24e952018-05-24 11:59:30 +0200541 * With this strategy, you must not encrypt more than 2**128
542 * blocks of data with the same key.
543 *
544 * 2. You can encrypt separate messages by dividing the \p
545 * nonce_counter buffer in two areas: the first one used for a
546 * per-message nonce, handled by yourself, and the second one
547 * updated by this function internally.
548 *
549 * For example, you might reserve the first 12 bytes for the
550 * per-message nonce, and the last 4 bytes for internal use. In that
551 * case, before calling this function on a new message you need to
552 * set the first 12 bytes of \p nonce_counter to your chosen nonce
553 * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
554 * stream_block to be ignored). That way, you can encrypt at most
555 * 2**96 messages of up to 2**32 blocks each with the same key.
556 *
557 * The per-message nonce (or information sufficient to reconstruct
558 * it) needs to be communicated with the ciphertext and must be unique.
559 * The recommended way to ensure uniqueness is to use a message
560 * counter. An alternative is to generate random nonces, but this
561 * limits the number of messages that can be securely encrypted:
562 * for example, with 96-bit random nonces, you should not encrypt
563 * more than 2**32 messages with the same key.
564 *
565 * Note that for both stategies, sizes are measured in blocks and
566 * that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000567 *
Manuel Pégourié-Gonnardfa0c47d2018-05-24 19:02:06 +0200568 * \warning Upon return, \p stream_block contains sensitive data. Its
569 * content must not be written to insecure storage and should be
570 * securely discarded as soon as it's no longer needed.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000571 *
Rose Zadik7f441272018-01-22 11:48:23 +0000572 * \param ctx The AES context to use for encryption or decryption.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100573 * It must be initialized and bound to a key.
Rose Zadik7f441272018-01-22 11:48:23 +0000574 * \param length The length of the input data.
575 * \param nc_off The offset in the current \p stream_block, for
576 * resuming within the current cipher stream. The
577 * offset pointer should be 0 at the start of a stream.
Manuel Pégourié-Gonnard2bc535b2018-12-13 11:08:36 +0100578 * It must point to a valid \c size_t.
Rose Zadik7f441272018-01-22 11:48:23 +0000579 * \param nonce_counter The 128-bit nonce and counter.
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 stream_block The saved stream block for resuming. This is
582 * overwritten by the function.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100583 * It must be a readable-writeable buffer of \c 16 Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000584 * \param input The buffer holding the input data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100585 * It must be readable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000586 * \param output The buffer holding the output data.
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100587 * It must be writeable and of size \p length Bytes.
Rose Zadik7f441272018-01-22 11:48:23 +0000588 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100589 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000590 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200591int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000592 size_t length,
593 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000594 unsigned char nonce_counter[16],
595 unsigned char stream_block[16],
596 const unsigned char *input,
597 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200599
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200600/**
Rose Zadik7f441272018-01-22 11:48:23 +0000601 * \brief Internal AES block encryption function. This is only
602 * exposed to allow overriding it using
603 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200604 *
Rose Zadik7f441272018-01-22 11:48:23 +0000605 * \param ctx The AES context to use for encryption.
606 * \param input The plaintext block.
607 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000608 *
Rose Zadik7f441272018-01-22 11:48:23 +0000609 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200610 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200611 */
Andres AGf5bf7182017-03-03 14:09:56 +0000612int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
613 const unsigned char input[16],
614 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200615
616/**
Rose Zadik7f441272018-01-22 11:48:23 +0000617 * \brief Internal AES block decryption function. This is only
618 * exposed to allow overriding it using see
619 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200620 *
Rose Zadik7f441272018-01-22 11:48:23 +0000621 * \param ctx The AES context to use for decryption.
622 * \param input The ciphertext block.
623 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000624 *
Rose Zadik7f441272018-01-22 11:48:23 +0000625 * \return \c 0 on success.
Arto Kinnunen6ce49882019-12-03 13:56:06 +0200626 * \return #MBEDTLS_ERR_PLATFORM_FAULT_DETECTED in case of error.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200627 */
Andres AGf5bf7182017-03-03 14:09:56 +0000628int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
629 const unsigned char input[16],
630 unsigned char output[16] );
631
632#if !defined(MBEDTLS_DEPRECATED_REMOVED)
633#if defined(MBEDTLS_DEPRECATED_WARNING)
634#define MBEDTLS_DEPRECATED __attribute__((deprecated))
635#else
636#define MBEDTLS_DEPRECATED
637#endif
638/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100639 * \brief Deprecated internal AES block encryption function
640 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000641 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100642 * \deprecated Superseded by mbedtls_internal_aes_encrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000643 *
Rose Zadik7f441272018-01-22 11:48:23 +0000644 * \param ctx The AES context to use for encryption.
645 * \param input Plaintext block.
646 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000647 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100648MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
649 const unsigned char input[16],
650 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000651
652/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100653 * \brief Deprecated internal AES block decryption function
654 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000655 *
Manuel Pégourié-Gonnardb66e7db2018-12-18 09:57:18 +0100656 * \deprecated Superseded by mbedtls_internal_aes_decrypt()
Andres AGf5bf7182017-03-03 14:09:56 +0000657 *
Rose Zadik7f441272018-01-22 11:48:23 +0000658 * \param ctx The AES context to use for decryption.
659 * \param input Ciphertext block.
660 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000661 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100662MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
663 const unsigned char input[16],
664 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000665
666#undef MBEDTLS_DEPRECATED
667#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200668
Ron Eldorfa8f6352017-06-20 15:48:46 +0300669
670#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000671/**
Rose Zadik7f441272018-01-22 11:48:23 +0000672 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000673 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100674 * \return \c 0 on success.
675 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000676 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200677int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000678
Ron Eldorfa8f6352017-06-20 15:48:46 +0300679#endif /* MBEDTLS_SELF_TEST */
680
Paul Bakker5121ce52009-01-03 21:22:43 +0000681#ifdef __cplusplus
682}
683#endif
684
685#endif /* aes.h */