blob: e7b95105f13e1da8cd1f27b2837a10272704cb2c [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>.
Darryl Greena40a1012018-01-05 15:33:17 +000016 */
Rose Zadik5ad7aea2018-03-26 12:00:09 +010017
Rose Zadik7f441272018-01-22 11:48:23 +000018/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020019 * SPDX-License-Identifier: Apache-2.0
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may
22 * not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000032 *
Rose Zadik7f441272018-01-22 11:48:23 +000033 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000034 */
Rose Zadik7f441272018-01-22 11:48:23 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#ifndef MBEDTLS_AES_H
37#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000038
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020040#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020041#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020043#endif
Paul Bakker90995b52013-06-24 19:20:35 +020044
Rich Evans00ab4702015-02-06 13:43:58 +000045#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020046#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000047
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010048/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000049#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
50#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000051
Andres Amaya Garciac5380642017-11-28 19:57:51 +000052/* Error codes in range 0x0020-0x0022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
54#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000055
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010056/* Error codes in range 0x0023-0x0025 */
Rose Zadik7f441272018-01-22 11:48:23 +000057#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010058#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Simon Butcher1a925bc2018-05-14 13:58:22 +010059#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0027 /**< Invalid
60input data. */
61
62#if defined( MBEDTLS_CHECK_PARAMS )
63#define MBEDTLS_AES_VALIDATE( cond ) do{ if( !(cond) ) \
64 return MBEDTLS_ERR_AES_BAD_INPUT_DATA; \
65 } while(0);
66#else
67/* No validation of parameters will be performed */
68#define MBEDTLS_AES_VALIDATE( cond)
69#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000070
Andres AGf5bf7182017-03-03 14:09:56 +000071#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
72 !defined(inline) && !defined(__cplusplus)
73#define inline __inline
74#endif
75
Paul Bakker407a0da2013-06-27 14:29:21 +020076#ifdef __cplusplus
77extern "C" {
78#endif
79
Ron Eldorb2aacec2017-05-18 16:53:08 +030080#if !defined(MBEDTLS_AES_ALT)
81// Regular implementation
82//
83
Paul Bakker5121ce52009-01-03 21:22:43 +000084/**
Rose Zadik7f441272018-01-22 11:48:23 +000085 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000086 */
87typedef struct
88{
Rose Zadik7f441272018-01-22 11:48:23 +000089 int nr; /*!< The number of rounds. */
90 uint32_t *rk; /*!< AES round keys. */
91 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
92 hold 32 extra Bytes, which can be used for
93 one of the following purposes:
94 <ul><li>Alignment if VIA padlock is
95 used.</li>
96 <li>Simplifying key expansion in the 256-bit
97 case by generating an extra round key.
98 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +000099}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
Ron Eldorb2aacec2017-05-18 16:53:08 +0300102#else /* MBEDTLS_AES_ALT */
103#include "aes_alt.h"
104#endif /* MBEDTLS_AES_ALT */
105
Paul Bakker5121ce52009-01-03 21:22:43 +0000106/**
Rose Zadik7f441272018-01-22 11:48:23 +0000107 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200108 *
Rose Zadik7f441272018-01-22 11:48:23 +0000109 * It must be the first API called before using
110 * the context.
111 *
112 * \param ctx The AES context to initialize.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200113 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200115
116/**
Rose Zadik7f441272018-01-22 11:48:23 +0000117 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200118 *
Rose Zadik7f441272018-01-22 11:48:23 +0000119 * \param ctx The AES context to clear.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200120 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200122
123/**
Rose Zadik7f441272018-01-22 11:48:23 +0000124 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000125 *
Rose Zadik7f441272018-01-22 11:48:23 +0000126 * \param ctx The AES context to which the key should be bound.
127 * \param key The encryption key.
128 * \param keybits The size of data passed in bits. Valid options are:
129 * <ul><li>128 bits</li>
130 * <li>192 bits</li>
131 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000132 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100133 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100134 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000135 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200137 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000138
139/**
Rose Zadik7f441272018-01-22 11:48:23 +0000140 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000141 *
Rose Zadik7f441272018-01-22 11:48:23 +0000142 * \param ctx The AES context to which the key should be bound.
143 * \param key The decryption key.
144 * \param keybits The size of data passed. Valid options are:
145 * <ul><li>128 bits</li>
146 * <li>192 bits</li>
147 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000148 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100149 * \return \c 0 on success.
150 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200153 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000154
155/**
Rose Zadik7f441272018-01-22 11:48:23 +0000156 * \brief This function performs an AES single-block encryption or
157 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000158 *
Rose Zadik7f441272018-01-22 11:48:23 +0000159 * It performs the operation defined in the \p mode parameter
160 * (encrypt or decrypt), on the input data buffer defined in
161 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000162 *
Rose Zadik7f441272018-01-22 11:48:23 +0000163 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
164 * mbedtls_aes_setkey_dec() must be called before the first
165 * call to this API with the same context.
166 *
167 * \param ctx The AES context to use for encryption or decryption.
168 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
169 * #MBEDTLS_AES_DECRYPT.
170 * \param input The 16-Byte buffer holding the input data.
171 * \param output The 16-Byte buffer holding the output data.
172
173 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000174 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000176 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000177 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000178 unsigned char output[16] );
179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000181/**
Rose Zadik7f441272018-01-22 11:48:23 +0000182 * \brief This function performs an AES-CBC encryption or decryption operation
183 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000184 *
Rose Zadik7f441272018-01-22 11:48:23 +0000185 * It performs the operation defined in the \p mode
186 * parameter (encrypt/decrypt), on the input data buffer defined in
187 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000188 *
Rose Zadik7f441272018-01-22 11:48:23 +0000189 * It can be called as many times as needed, until all the input
190 * data is processed. mbedtls_aes_init(), and either
191 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
192 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000193 *
Rose Zadik7f441272018-01-22 11:48:23 +0000194 * \note This function operates on aligned blocks, that is, the input size
195 * must be a multiple of the AES block size of 16 Bytes.
196 *
197 * \note Upon exit, the content of the IV is updated so that you can
198 * call the same function again on the next
199 * block(s) of data and get the same result as if it was
200 * encrypted in one call. This allows a "streaming" usage.
201 * If you need to retain the contents of the IV, you should
202 * either save it manually or use the cipher module instead.
203 *
204 *
205 * \param ctx The AES context to use for encryption or decryption.
206 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
207 * #MBEDTLS_AES_DECRYPT.
208 * \param length The length of the input data in Bytes. This must be a
209 * multiple of the block size (16 Bytes).
210 * \param iv Initialization vector (updated after use).
211 * \param input The buffer holding the input data.
212 * \param output The buffer holding the output data.
213 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100214 * \return \c 0 on success.
215 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000216 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000217 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000219 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000220 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000221 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000222 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000223 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000225
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000227/**
Rose Zadik7f441272018-01-22 11:48:23 +0000228 * \brief This function performs an AES-CFB128 encryption or decryption
229 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000230 *
Rose Zadik7f441272018-01-22 11:48:23 +0000231 * It performs the operation defined in the \p mode
232 * parameter (encrypt or decrypt), on the input data buffer
233 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000234 *
Rose Zadik7f441272018-01-22 11:48:23 +0000235 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
236 * regardless of whether you are performing an encryption or decryption
237 * operation, that is, regardless of the \p mode parameter. This is
238 * because CFB mode uses the same key schedule for encryption and
239 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000240 *
Rose Zadik7f441272018-01-22 11:48:23 +0000241 * \note Upon exit, the content of the IV is updated so that you can
242 * call the same function again on the next
243 * block(s) of data and get the same result as if it was
244 * encrypted in one call. This allows a "streaming" usage.
245 * If you need to retain the contents of the
246 * IV, you must either save it manually or use the cipher
247 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000248 *
Rose Zadik7f441272018-01-22 11:48:23 +0000249 *
250 * \param ctx The AES context to use for encryption or decryption.
251 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
252 * #MBEDTLS_AES_DECRYPT.
253 * \param length The length of the input data.
254 * \param iv_off The offset in IV (updated after use).
255 * \param iv The initialization vector (updated after use).
256 * \param input The buffer holding the input data.
257 * \param output The buffer holding the output data.
258 *
259 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000260 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000262 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000263 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000264 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000265 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000266 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 unsigned char *output );
268
Paul Bakker9a736322012-11-14 12:39:52 +0000269/**
Rose Zadik7f441272018-01-22 11:48:23 +0000270 * \brief This function performs an AES-CFB8 encryption or decryption
271 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100272 *
Rose Zadik7f441272018-01-22 11:48:23 +0000273 * It performs the operation defined in the \p mode
274 * parameter (encrypt/decrypt), on the input data buffer defined
275 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100276 *
Rose Zadik7f441272018-01-22 11:48:23 +0000277 * Due to the nature of CFB, you must use the same key schedule for
278 * both encryption and decryption operations. Therefore, you must
279 * use the context initialized with mbedtls_aes_setkey_enc() for
280 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000281 *
Rose Zadik7f441272018-01-22 11:48:23 +0000282 * \note Upon exit, the content of the IV is updated so that you can
283 * call the same function again on the next
284 * block(s) of data and get the same result as if it was
285 * encrypted in one call. This allows a "streaming" usage.
286 * If you need to retain the contents of the
287 * IV, you should either save it manually or use the cipher
288 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100289 *
Rose Zadik7f441272018-01-22 11:48:23 +0000290 *
291 * \param ctx The AES context to use for encryption or decryption.
292 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
293 * #MBEDTLS_AES_DECRYPT
294 * \param length The length of the input data.
295 * \param iv The initialization vector (updated after use).
296 * \param input The buffer holding the input data.
297 * \param output The buffer holding the output data.
298 *
299 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100300 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100302 int mode,
303 size_t length,
304 unsigned char iv[16],
305 const unsigned char *input,
306 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100308
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100310/**
Rose Zadik7f441272018-01-22 11:48:23 +0000311 * \brief This function performs an AES-CTR encryption or decryption
312 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000313 *
Rose Zadik7f441272018-01-22 11:48:23 +0000314 * This function performs the operation defined in the \p mode
315 * parameter (encrypt/decrypt), on the input data buffer
316 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000317 *
Rose Zadik7f441272018-01-22 11:48:23 +0000318 * Due to the nature of CTR, you must use the same key schedule
319 * for both encryption and decryption operations. Therefore, you
320 * must use the context initialized with mbedtls_aes_setkey_enc()
321 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000322 *
Rose Zadik7f441272018-01-22 11:48:23 +0000323 * \warning You must keep the maximum use of your counter in mind.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000324 *
Rose Zadik7f441272018-01-22 11:48:23 +0000325 * \param ctx The AES context to use for encryption or decryption.
326 * \param length The length of the input data.
327 * \param nc_off The offset in the current \p stream_block, for
328 * resuming within the current cipher stream. The
329 * offset pointer should be 0 at the start of a stream.
330 * \param nonce_counter The 128-bit nonce and counter.
331 * \param stream_block The saved stream block for resuming. This is
332 * overwritten by the function.
333 * \param input The buffer holding the input data.
334 * \param output The buffer holding the output data.
335 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100336 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000337 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000339 size_t length,
340 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000341 unsigned char nonce_counter[16],
342 unsigned char stream_block[16],
343 const unsigned char *input,
344 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200346
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200347/**
Rose Zadik7f441272018-01-22 11:48:23 +0000348 * \brief Internal AES block encryption function. This is only
349 * exposed to allow overriding it using
350 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200351 *
Rose Zadik7f441272018-01-22 11:48:23 +0000352 * \param ctx The AES context to use for encryption.
353 * \param input The plaintext block.
354 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000355 *
Rose Zadik7f441272018-01-22 11:48:23 +0000356 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200357 */
Andres AGf5bf7182017-03-03 14:09:56 +0000358int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
359 const unsigned char input[16],
360 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200361
362/**
Rose Zadik7f441272018-01-22 11:48:23 +0000363 * \brief Internal AES block decryption function. This is only
364 * exposed to allow overriding it using see
365 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200366 *
Rose Zadik7f441272018-01-22 11:48:23 +0000367 * \param ctx The AES context to use for decryption.
368 * \param input The ciphertext block.
369 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000370 *
Rose Zadik7f441272018-01-22 11:48:23 +0000371 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200372 */
Andres AGf5bf7182017-03-03 14:09:56 +0000373int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
374 const unsigned char input[16],
375 unsigned char output[16] );
376
377#if !defined(MBEDTLS_DEPRECATED_REMOVED)
378#if defined(MBEDTLS_DEPRECATED_WARNING)
379#define MBEDTLS_DEPRECATED __attribute__((deprecated))
380#else
381#define MBEDTLS_DEPRECATED
382#endif
383/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100384 * \brief Deprecated internal AES block encryption function
385 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000386 *
Rose Zadik7f441272018-01-22 11:48:23 +0000387 * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000388 *
Rose Zadik7f441272018-01-22 11:48:23 +0000389 * \param ctx The AES context to use for encryption.
390 * \param input Plaintext block.
391 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000392 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100393MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
394 const unsigned char input[16],
395 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000396
397/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100398 * \brief Deprecated internal AES block decryption function
399 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000400 *
Rose Zadik7f441272018-01-22 11:48:23 +0000401 * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000402 *
Rose Zadik7f441272018-01-22 11:48:23 +0000403 * \param ctx The AES context to use for decryption.
404 * \param input Ciphertext block.
405 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000406 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100407MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
408 const unsigned char input[16],
409 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000410
411#undef MBEDTLS_DEPRECATED
412#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200413
Paul Bakker5121ce52009-01-03 21:22:43 +0000414/**
Rose Zadik7f441272018-01-22 11:48:23 +0000415 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000416 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100417 * \return \c 0 on success.
418 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000419 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200420int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000421
422#ifdef __cplusplus
423}
424#endif
425
426#endif /* aes.h */