blob: c82d39a402f800586e7550e0b2ba06f5952b3b2f [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. */
Paul Bakker5121ce52009-01-03 21:22:43 +000059
Andres AGf5bf7182017-03-03 14:09:56 +000060#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
61 !defined(inline) && !defined(__cplusplus)
62#define inline __inline
63#endif
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if !defined(MBEDTLS_AES_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020066// Regular implementation
67//
68
Paul Bakker407a0da2013-06-27 14:29:21 +020069#ifdef __cplusplus
70extern "C" {
71#endif
72
Paul Bakker5121ce52009-01-03 21:22:43 +000073/**
Rose Zadik7f441272018-01-22 11:48:23 +000074 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000075 */
76typedef struct
77{
Rose Zadik7f441272018-01-22 11:48:23 +000078 int nr; /*!< The number of rounds. */
79 uint32_t *rk; /*!< AES round keys. */
80 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
81 hold 32 extra Bytes, which can be used for
82 one of the following purposes:
83 <ul><li>Alignment if VIA padlock is
84 used.</li>
85 <li>Simplifying key expansion in the 256-bit
86 case by generating an extra round key.
87 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +000088}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000090
Paul Bakker5121ce52009-01-03 21:22:43 +000091/**
Rose Zadik7f441272018-01-22 11:48:23 +000092 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020093 *
Rose Zadik7f441272018-01-22 11:48:23 +000094 * It must be the first API called before using
95 * the context.
96 *
97 * \param ctx The AES context to initialize.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020098 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200100
101/**
Rose Zadik7f441272018-01-22 11:48:23 +0000102 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200103 *
Rose Zadik7f441272018-01-22 11:48:23 +0000104 * \param ctx The AES context to clear.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200105 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200107
108/**
Rose Zadik7f441272018-01-22 11:48:23 +0000109 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 *
Rose Zadik7f441272018-01-22 11:48:23 +0000111 * \param ctx The AES context to which the key should be bound.
112 * \param key The encryption key.
113 * \param keybits The size of data passed in bits. Valid options are:
114 * <ul><li>128 bits</li>
115 * <li>192 bits</li>
116 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000117 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100118 * \return \c 0 on success.
119 * #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000120 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200122 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000123
124/**
Rose Zadik7f441272018-01-22 11:48:23 +0000125 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 *
Rose Zadik7f441272018-01-22 11:48:23 +0000127 * \param ctx The AES context to which the key should be bound.
128 * \param key The decryption key.
129 * \param keybits The size of data passed. Valid options are:
130 * <ul><li>128 bits</li>
131 * <li>192 bits</li>
132 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000133 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100134 * \return \c 0 on success.
135 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200138 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000139
140/**
Rose Zadik7f441272018-01-22 11:48:23 +0000141 * \brief This function performs an AES single-block encryption or
142 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000143 *
Rose Zadik7f441272018-01-22 11:48:23 +0000144 * It performs the operation defined in the \p mode parameter
145 * (encrypt or decrypt), on the input data buffer defined in
146 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000147 *
Rose Zadik7f441272018-01-22 11:48:23 +0000148 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
149 * mbedtls_aes_setkey_dec() must be called before the first
150 * call to this API with the same context.
151 *
152 * \param ctx The AES context to use for encryption or decryption.
153 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
154 * #MBEDTLS_AES_DECRYPT.
155 * \param input The 16-Byte buffer holding the input data.
156 * \param output The 16-Byte buffer holding the output data.
157
158 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000159 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000161 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000162 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 unsigned char output[16] );
164
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000166/**
Rose Zadik7f441272018-01-22 11:48:23 +0000167 * \brief This function performs an AES-CBC encryption or decryption operation
168 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000169 *
Rose Zadik7f441272018-01-22 11:48:23 +0000170 * It performs the operation defined in the \p mode
171 * parameter (encrypt/decrypt), on the input data buffer defined in
172 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000173 *
Rose Zadik7f441272018-01-22 11:48:23 +0000174 * It can be called as many times as needed, until all the input
175 * data is processed. mbedtls_aes_init(), and either
176 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
177 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000178 *
Rose Zadik7f441272018-01-22 11:48:23 +0000179 * \note This function operates on aligned blocks, that is, the input size
180 * must be a multiple of the AES block size of 16 Bytes.
181 *
182 * \note Upon exit, the content of the IV is updated so that you can
183 * call the same function again on the next
184 * block(s) of data and get the same result as if it was
185 * encrypted in one call. This allows a "streaming" usage.
186 * If you need to retain the contents of the IV, you should
187 * either save it manually or use the cipher module instead.
188 *
189 *
190 * \param ctx The AES context to use for encryption or decryption.
191 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
192 * #MBEDTLS_AES_DECRYPT.
193 * \param length The length of the input data in Bytes. This must be a
194 * multiple of the block size (16 Bytes).
195 * \param iv Initialization vector (updated after use).
196 * \param input The buffer holding the input data.
197 * \param output The buffer holding the output data.
198 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100199 * \return \c 0 on success.
200 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000201 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000202 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000204 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000205 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000207 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000208 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000212/**
Rose Zadik7f441272018-01-22 11:48:23 +0000213 * \brief This function performs an AES-CFB128 encryption or decryption
214 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000215 *
Rose Zadik7f441272018-01-22 11:48:23 +0000216 * It performs the operation defined in the \p mode
217 * parameter (encrypt or decrypt), on the input data buffer
218 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000219 *
Rose Zadik7f441272018-01-22 11:48:23 +0000220 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
221 * regardless of whether you are performing an encryption or decryption
222 * operation, that is, regardless of the \p mode parameter. This is
223 * because CFB mode uses the same key schedule for encryption and
224 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000225 *
Rose Zadik7f441272018-01-22 11:48:23 +0000226 * \note Upon exit, the content of the IV is updated so that you can
227 * call the same function again on the next
228 * block(s) of data and get the same result as if it was
229 * encrypted in one call. This allows a "streaming" usage.
230 * If you need to retain the contents of the
231 * IV, you must either save it manually or use the cipher
232 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000233 *
Rose Zadik7f441272018-01-22 11:48:23 +0000234 *
235 * \param ctx The AES context to use for encryption or decryption.
236 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
237 * #MBEDTLS_AES_DECRYPT.
238 * \param length The length of the input data.
239 * \param iv_off The offset in IV (updated after use).
240 * \param iv The initialization vector (updated after use).
241 * \param input The buffer holding the input data.
242 * \param output The buffer holding the output data.
243 *
244 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000247 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000248 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000249 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000250 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000251 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000252 unsigned char *output );
253
Paul Bakker9a736322012-11-14 12:39:52 +0000254/**
Rose Zadik7f441272018-01-22 11:48:23 +0000255 * \brief This function performs an AES-CFB8 encryption or decryption
256 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100257 *
Rose Zadik7f441272018-01-22 11:48:23 +0000258 * It performs the operation defined in the \p mode
259 * parameter (encrypt/decrypt), on the input data buffer defined
260 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100261 *
Rose Zadik7f441272018-01-22 11:48:23 +0000262 * Due to the nature of CFB, you must use the same key schedule for
263 * both encryption and decryption operations. Therefore, you must
264 * use the context initialized with mbedtls_aes_setkey_enc() for
265 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000266 *
Rose Zadik7f441272018-01-22 11:48:23 +0000267 * \note Upon exit, the content of the IV is updated so that you can
268 * call the same function again on the next
269 * block(s) of data and get the same result as if it was
270 * encrypted in one call. This allows a "streaming" usage.
271 * If you need to retain the contents of the
272 * IV, you should either save it manually or use the cipher
273 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100274 *
Rose Zadik7f441272018-01-22 11:48:23 +0000275 *
276 * \param ctx The AES context to use for encryption or decryption.
277 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
278 * #MBEDTLS_AES_DECRYPT
279 * \param length The length of the input data.
280 * \param iv The initialization vector (updated after use).
281 * \param input The buffer holding the input data.
282 * \param output The buffer holding the output data.
283 *
284 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100285 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100287 int mode,
288 size_t length,
289 unsigned char iv[16],
290 const unsigned char *input,
291 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100295/**
Rose Zadik7f441272018-01-22 11:48:23 +0000296 * \brief This function performs an AES-CTR encryption or decryption
297 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000298 *
Rose Zadik7f441272018-01-22 11:48:23 +0000299 * This function performs the operation defined in the \p mode
300 * parameter (encrypt/decrypt), on the input data buffer
301 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000302 *
Rose Zadik7f441272018-01-22 11:48:23 +0000303 * Due to the nature of CTR, you must use the same key schedule
304 * for both encryption and decryption operations. Therefore, you
305 * must use the context initialized with mbedtls_aes_setkey_enc()
306 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000307 *
Rose Zadik7f441272018-01-22 11:48:23 +0000308 * \warning You must keep the maximum use of your counter in mind.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000309 *
Rose Zadik7f441272018-01-22 11:48:23 +0000310 * \param ctx The AES context to use for encryption or decryption.
311 * \param length The length of the input data.
312 * \param nc_off The offset in the current \p stream_block, for
313 * resuming within the current cipher stream. The
314 * offset pointer should be 0 at the start of a stream.
315 * \param nonce_counter The 128-bit nonce and counter.
316 * \param stream_block The saved stream block for resuming. This is
317 * overwritten by the function.
318 * \param input The buffer holding the input data.
319 * \param output The buffer holding the output data.
320 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100321 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000322 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000324 size_t length,
325 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000326 unsigned char nonce_counter[16],
327 unsigned char stream_block[16],
328 const unsigned char *input,
329 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200330#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200331
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200332/**
Rose Zadik7f441272018-01-22 11:48:23 +0000333 * \brief Internal AES block encryption function. This is only
334 * exposed to allow overriding it using
335 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200336 *
Rose Zadik7f441272018-01-22 11:48:23 +0000337 * \param ctx The AES context to use for encryption.
338 * \param input The plaintext block.
339 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000340 *
Rose Zadik7f441272018-01-22 11:48:23 +0000341 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200342 */
Andres AGf5bf7182017-03-03 14:09:56 +0000343int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
344 const unsigned char input[16],
345 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200346
347/**
Rose Zadik7f441272018-01-22 11:48:23 +0000348 * \brief Internal AES block decryption function. This is only
349 * exposed to allow overriding it using see
350 * \c MBEDTLS_AES_DECRYPT_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 decryption.
353 * \param input The ciphertext block.
354 * \param output The output (plaintext) 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_decrypt( mbedtls_aes_context *ctx,
359 const unsigned char input[16],
360 unsigned char output[16] );
361
362#if !defined(MBEDTLS_DEPRECATED_REMOVED)
363#if defined(MBEDTLS_DEPRECATED_WARNING)
364#define MBEDTLS_DEPRECATED __attribute__((deprecated))
365#else
366#define MBEDTLS_DEPRECATED
367#endif
368/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100369 * \brief Deprecated internal AES block encryption function
370 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000371 *
Rose Zadik7f441272018-01-22 11:48:23 +0000372 * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000373 *
Rose Zadik7f441272018-01-22 11:48:23 +0000374 * \param ctx The AES context to use for encryption.
375 * \param input Plaintext block.
376 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000377 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100378MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
379 const unsigned char input[16],
380 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000381
382/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100383 * \brief Deprecated internal AES block decryption function
384 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000385 *
Rose Zadik7f441272018-01-22 11:48:23 +0000386 * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000387 *
Rose Zadik7f441272018-01-22 11:48:23 +0000388 * \param ctx The AES context to use for decryption.
389 * \param input Ciphertext block.
390 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000391 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100392MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
393 const unsigned char input[16],
394 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000395
396#undef MBEDTLS_DEPRECATED
397#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200398
Paul Bakker90995b52013-06-24 19:20:35 +0200399#ifdef __cplusplus
400}
401#endif
402
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200403#else /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200404#include "aes_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405#endif /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200406
407#ifdef __cplusplus
408extern "C" {
409#endif
410
Paul Bakker5121ce52009-01-03 21:22:43 +0000411/**
Rose Zadik7f441272018-01-22 11:48:23 +0000412 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000413 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100414 * \return \c 0 on success.
415 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000416 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000418
419#ifdef __cplusplus
420}
421#endif
422
423#endif /* aes.h */