blob: 46016dcb7f70d1a0851247066626d0c730d232cd [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file aes.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Rose Zadik7f441272018-01-22 11:48:23 +00004 * \brief The Advanced Encryption Standard (AES) specifies a FIPS-approved
5 * cryptographic algorithm that can be used to protect electronic
6 * data.
7 *
8 * The AES algorithm is a symmetric block cipher that can
9 * encrypt and decrypt information. For more information, see
10 * <em>FIPS Publication 197: Advanced Encryption Standard</em> and
11 * <em>ISO/IEC 18033-2:2006: Information technology -- Security
12 * techniques -- Encryption algorithms -- Part 2: Asymmetric
13 * ciphers</em>.
Darryl Greena40a1012018-01-05 15:33:17 +000014 */
Rose Zadik7f441272018-01-22 11:48:23 +000015/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020016 * SPDX-License-Identifier: Apache-2.0
17 *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may
19 * not use this file except in compliance with the License.
20 * You may obtain a copy of the License at
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000029 *
Rose Zadik7f441272018-01-22 11:48:23 +000030 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000031 */
Rose Zadik7f441272018-01-22 11:48:23 +000032
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#ifndef MBEDTLS_AES_H
34#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020037#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020038#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020040#endif
Paul Bakker90995b52013-06-24 19:20:35 +020041
Rich Evans00ab4702015-02-06 13:43:58 +000042#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020043#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000044
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010045/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000046#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
47#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000048
Andres Amaya Garciac5380642017-11-28 19:57:51 +000049/* Error codes in range 0x0020-0x0022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
51#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000052
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010053/* Error codes in range 0x0023-0x0025 */
Rose Zadik7f441272018-01-22 11:48:23 +000054#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010055#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Andres AGf5bf7182017-03-03 14:09:56 +000057#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
58 !defined(inline) && !defined(__cplusplus)
59#define inline __inline
60#endif
61
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#if !defined(MBEDTLS_AES_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020063// Regular implementation
64//
65
Paul Bakker407a0da2013-06-27 14:29:21 +020066#ifdef __cplusplus
67extern "C" {
68#endif
69
Paul Bakker5121ce52009-01-03 21:22:43 +000070/**
Rose Zadik7f441272018-01-22 11:48:23 +000071 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000072 */
73typedef struct
74{
Rose Zadik7f441272018-01-22 11:48:23 +000075 int nr; /*!< The number of rounds. */
76 uint32_t *rk; /*!< AES round keys. */
77 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
78 hold 32 extra Bytes, which can be used for
79 one of the following purposes:
80 <ul><li>Alignment if VIA padlock is
81 used.</li>
82 <li>Simplifying key expansion in the 256-bit
83 case by generating an extra round key.
84 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +000085}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000087
Paul Bakker5121ce52009-01-03 21:22:43 +000088/**
Rose Zadik7f441272018-01-22 11:48:23 +000089 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020090 *
Rose Zadik7f441272018-01-22 11:48:23 +000091 * It must be the first API called before using
92 * the context.
93 *
94 * \param ctx The AES context to initialize.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020095 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020097
98/**
Rose Zadik7f441272018-01-22 11:48:23 +000099 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200100 *
Rose Zadik7f441272018-01-22 11:48:23 +0000101 * \param ctx The AES context to clear.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200102 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200104
105/**
Rose Zadik7f441272018-01-22 11:48:23 +0000106 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 *
Rose Zadik7f441272018-01-22 11:48:23 +0000108 * \param ctx The AES context to which the key should be bound.
109 * \param key The encryption key.
110 * \param keybits The size of data passed in bits. Valid options are:
111 * <ul><li>128 bits</li>
112 * <li>192 bits</li>
113 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000114 *
Rose Zadik7f441272018-01-22 11:48:23 +0000115 * \return \c 0 on success or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
116 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000117 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200119 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000120
121/**
Rose Zadik7f441272018-01-22 11:48:23 +0000122 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 *
Rose Zadik7f441272018-01-22 11:48:23 +0000124 * \param ctx The AES context to which the key should be bound.
125 * \param key The decryption key.
126 * \param keybits The size of data passed. Valid options are:
127 * <ul><li>128 bits</li>
128 * <li>192 bits</li>
129 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000130 *
Rose Zadik7f441272018-01-22 11:48:23 +0000131 * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200134 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
136/**
Rose Zadik7f441272018-01-22 11:48:23 +0000137 * \brief This function performs an AES single-block encryption or
138 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000139 *
Rose Zadik7f441272018-01-22 11:48:23 +0000140 * It performs the operation defined in the \p mode parameter
141 * (encrypt or decrypt), on the input data buffer defined in
142 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000143 *
Rose Zadik7f441272018-01-22 11:48:23 +0000144 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
145 * mbedtls_aes_setkey_dec() must be called before the first
146 * call to this API with the same context.
147 *
148 * \param ctx The AES context to use for encryption or decryption.
149 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
150 * #MBEDTLS_AES_DECRYPT.
151 * \param input The 16-Byte buffer holding the input data.
152 * \param output The 16-Byte buffer holding the output data.
153
154 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000155 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000157 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000158 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000159 unsigned char output[16] );
160
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000162/**
Rose Zadik7f441272018-01-22 11:48:23 +0000163 * \brief This function performs an AES-CBC encryption or decryption operation
164 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000165 *
Rose Zadik7f441272018-01-22 11:48:23 +0000166 * It performs the operation defined in the \p mode
167 * parameter (encrypt/decrypt), on the input data buffer defined in
168 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000169 *
Rose Zadik7f441272018-01-22 11:48:23 +0000170 * It can be called as many times as needed, until all the input
171 * data is processed. mbedtls_aes_init(), and either
172 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
173 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000174 *
Rose Zadik7f441272018-01-22 11:48:23 +0000175 * \note This function operates on aligned blocks, that is, the input size
176 * must be a multiple of the AES block size of 16 Bytes.
177 *
178 * \note Upon exit, the content of the IV is updated so that you can
179 * call the same function again on the next
180 * block(s) of data and get the same result as if it was
181 * encrypted in one call. This allows a "streaming" usage.
182 * If you need to retain the contents of the IV, you should
183 * either save it manually or use the cipher module instead.
184 *
185 *
186 * \param ctx The AES context to use for encryption or decryption.
187 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
188 * #MBEDTLS_AES_DECRYPT.
189 * \param length The length of the input data in Bytes. This must be a
190 * multiple of the block size (16 Bytes).
191 * \param iv Initialization vector (updated after use).
192 * \param input The buffer holding the input data.
193 * \param output The buffer holding the output data.
194 *
195 * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
196 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000197 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000199 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000200 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000201 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000202 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000203 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000207/**
Rose Zadik7f441272018-01-22 11:48:23 +0000208 * \brief This function performs an AES-CFB128 encryption or decryption
209 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000210 *
Rose Zadik7f441272018-01-22 11:48:23 +0000211 * It performs the operation defined in the \p mode
212 * parameter (encrypt or decrypt), on the input data buffer
213 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000214 *
Rose Zadik7f441272018-01-22 11:48:23 +0000215 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
216 * regardless of whether you are performing an encryption or decryption
217 * operation, that is, regardless of the \p mode parameter. This is
218 * because CFB mode uses the same key schedule for encryption and
219 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000220 *
Rose Zadik7f441272018-01-22 11:48:23 +0000221 * \note Upon exit, the content of the IV is updated so that you can
222 * call the same function again on the next
223 * block(s) of data and get the same result as if it was
224 * encrypted in one call. This allows a "streaming" usage.
225 * If you need to retain the contents of the
226 * IV, you must either save it manually or use the cipher
227 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000228 *
Rose Zadik7f441272018-01-22 11:48:23 +0000229 *
230 * \param ctx The AES context to use for encryption or decryption.
231 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
232 * #MBEDTLS_AES_DECRYPT.
233 * \param length The length of the input data.
234 * \param iv_off The offset in IV (updated after use).
235 * \param iv The initialization vector (updated after use).
236 * \param input The buffer holding the input data.
237 * \param output The buffer holding the output data.
238 *
239 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000240 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000242 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000243 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000244 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000246 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000247 unsigned char *output );
248
Paul Bakker9a736322012-11-14 12:39:52 +0000249/**
Rose Zadik7f441272018-01-22 11:48:23 +0000250 * \brief This function performs an AES-CFB8 encryption or decryption
251 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100252 *
Rose Zadik7f441272018-01-22 11:48:23 +0000253 * It performs the operation defined in the \p mode
254 * parameter (encrypt/decrypt), on the input data buffer defined
255 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100256 *
Rose Zadik7f441272018-01-22 11:48:23 +0000257 * Due to the nature of CFB, you must use the same key schedule for
258 * both encryption and decryption operations. Therefore, you must
259 * use the context initialized with mbedtls_aes_setkey_enc() for
260 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000261 *
Rose Zadik7f441272018-01-22 11:48:23 +0000262 * \note Upon exit, the content of the IV is updated so that you can
263 * call the same function again on the next
264 * block(s) of data and get the same result as if it was
265 * encrypted in one call. This allows a "streaming" usage.
266 * If you need to retain the contents of the
267 * IV, you should either save it manually or use the cipher
268 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100269 *
Rose Zadik7f441272018-01-22 11:48:23 +0000270 *
271 * \param ctx The AES context to use for encryption or decryption.
272 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
273 * #MBEDTLS_AES_DECRYPT
274 * \param length The length of the input data.
275 * \param iv The initialization vector (updated after use).
276 * \param input The buffer holding the input data.
277 * \param output The buffer holding the output data.
278 *
279 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100280 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100282 int mode,
283 size_t length,
284 unsigned char iv[16],
285 const unsigned char *input,
286 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200287#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100288
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200289#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100290/**
Rose Zadik7f441272018-01-22 11:48:23 +0000291 * \brief This function performs an AES-CTR encryption or decryption
292 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000293 *
Rose Zadik7f441272018-01-22 11:48:23 +0000294 * This function performs the operation defined in the \p mode
295 * parameter (encrypt/decrypt), on the input data buffer
296 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000297 *
Rose Zadik7f441272018-01-22 11:48:23 +0000298 * Due to the nature of CTR, you must use the same key schedule
299 * for both encryption and decryption operations. Therefore, you
300 * must use the context initialized with mbedtls_aes_setkey_enc()
301 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000302 *
Rose Zadik7f441272018-01-22 11:48:23 +0000303 * \warning You must keep the maximum use of your counter in mind.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000304 *
Rose Zadik7f441272018-01-22 11:48:23 +0000305 * \param ctx The AES context to use for encryption or decryption.
306 * \param length The length of the input data.
307 * \param nc_off The offset in the current \p stream_block, for
308 * resuming within the current cipher stream. The
309 * offset pointer should be 0 at the start of a stream.
310 * \param nonce_counter The 128-bit nonce and counter.
311 * \param stream_block The saved stream block for resuming. This is
312 * overwritten by the function.
313 * \param input The buffer holding the input data.
314 * \param output The buffer holding the output data.
315 *
316 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000317 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000319 size_t length,
320 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000321 unsigned char nonce_counter[16],
322 unsigned char stream_block[16],
323 const unsigned char *input,
324 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200325#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200326
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200327/**
Rose Zadik7f441272018-01-22 11:48:23 +0000328 * \brief Internal AES block encryption function. This is only
329 * exposed to allow overriding it using
330 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200331 *
Rose Zadik7f441272018-01-22 11:48:23 +0000332 * \param ctx The AES context to use for encryption.
333 * \param input The plaintext block.
334 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000335 *
Rose Zadik7f441272018-01-22 11:48:23 +0000336 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200337 */
Andres AGf5bf7182017-03-03 14:09:56 +0000338int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
339 const unsigned char input[16],
340 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200341
342/**
Rose Zadik7f441272018-01-22 11:48:23 +0000343 * \brief Internal AES block decryption function. This is only
344 * exposed to allow overriding it using see
345 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200346 *
Rose Zadik7f441272018-01-22 11:48:23 +0000347 * \param ctx The AES context to use for decryption.
348 * \param input The ciphertext block.
349 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000350 *
Rose Zadik7f441272018-01-22 11:48:23 +0000351 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200352 */
Andres AGf5bf7182017-03-03 14:09:56 +0000353int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
354 const unsigned char input[16],
355 unsigned char output[16] );
356
357#if !defined(MBEDTLS_DEPRECATED_REMOVED)
358#if defined(MBEDTLS_DEPRECATED_WARNING)
359#define MBEDTLS_DEPRECATED __attribute__((deprecated))
360#else
361#define MBEDTLS_DEPRECATED
362#endif
363/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100364 * \brief Deprecated internal AES block encryption function
365 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000366 *
Rose Zadik7f441272018-01-22 11:48:23 +0000367 * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000368 *
Rose Zadik7f441272018-01-22 11:48:23 +0000369 * \param ctx The AES context to use for encryption.
370 * \param input Plaintext block.
371 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000372 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100373MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
374 const unsigned char input[16],
375 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000376
377/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100378 * \brief Deprecated internal AES block decryption function
379 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000380 *
Rose Zadik7f441272018-01-22 11:48:23 +0000381 * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000382 *
Rose Zadik7f441272018-01-22 11:48:23 +0000383 * \param ctx The AES context to use for decryption.
384 * \param input Ciphertext block.
385 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000386 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100387MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
388 const unsigned char input[16],
389 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000390
391#undef MBEDTLS_DEPRECATED
392#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200393
Paul Bakker90995b52013-06-24 19:20:35 +0200394#ifdef __cplusplus
395}
396#endif
397
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200398#else /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200399#include "aes_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200400#endif /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200401
402#ifdef __cplusplus
403extern "C" {
404#endif
405
Paul Bakker5121ce52009-01-03 21:22:43 +0000406/**
Rose Zadik7f441272018-01-22 11:48:23 +0000407 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000408 *
Rose Zadik7f441272018-01-22 11:48:23 +0000409 * \return \c 0 on success, or \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000410 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200411int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000412
413#ifdef __cplusplus
414}
415#endif
416
417#endif /* aes.h */