blob: 8b9280d97a01a5e1f65b1c48ceaabb581ef7a276 [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
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +000053/* Error codes in range 0x0021-0x0025 */
54#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
Rose Zadik7f441272018-01-22 11:48:23 +000055#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010056#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000057
Andres AGf5bf7182017-03-03 14:09:56 +000058#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
59 !defined(inline) && !defined(__cplusplus)
60#define inline __inline
61#endif
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if !defined(MBEDTLS_AES_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020064// Regular implementation
65//
66
Paul Bakker407a0da2013-06-27 14:29:21 +020067#ifdef __cplusplus
68extern "C" {
69#endif
70
Paul Bakker5121ce52009-01-03 21:22:43 +000071/**
Rose Zadik7f441272018-01-22 11:48:23 +000072 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +000073 */
74typedef struct
75{
Rose Zadik7f441272018-01-22 11:48:23 +000076 int nr; /*!< The number of rounds. */
77 uint32_t *rk; /*!< AES round keys. */
78 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
79 hold 32 extra Bytes, which can be used for
80 one of the following purposes:
81 <ul><li>Alignment if VIA padlock is
82 used.</li>
83 <li>Simplifying key expansion in the 256-bit
84 case by generating an extra round key.
85 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +000086}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000088
Paul Bakker5121ce52009-01-03 21:22:43 +000089/**
Rose Zadik7f441272018-01-22 11:48:23 +000090 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020091 *
Rose Zadik7f441272018-01-22 11:48:23 +000092 * It must be the first API called before using
93 * the context.
94 *
95 * \param ctx The AES context to initialize.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020096 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020098
99/**
Rose Zadik7f441272018-01-22 11:48:23 +0000100 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200101 *
Rose Zadik7f441272018-01-22 11:48:23 +0000102 * \param ctx The AES context to clear.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200103 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200105
106/**
Rose Zadik7f441272018-01-22 11:48:23 +0000107 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000108 *
Rose Zadik7f441272018-01-22 11:48:23 +0000109 * \param ctx The AES context to which the key should be bound.
110 * \param key The encryption key.
111 * \param keybits The size of data passed in bits. Valid options are:
112 * <ul><li>128 bits</li>
113 * <li>192 bits</li>
114 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000115 *
Rose Zadik7f441272018-01-22 11:48:23 +0000116 * \return \c 0 on success or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
117 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000118 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200120 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
122/**
Rose Zadik7f441272018-01-22 11:48:23 +0000123 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 *
Rose Zadik7f441272018-01-22 11:48:23 +0000125 * \param ctx The AES context to which the key should be bound.
126 * \param key The decryption key.
127 * \param keybits The size of data passed. Valid options are:
128 * <ul><li>128 bits</li>
129 * <li>192 bits</li>
130 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000131 *
Rose Zadik7f441272018-01-22 11:48:23 +0000132 * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200135 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000136
137/**
Rose Zadik7f441272018-01-22 11:48:23 +0000138 * \brief This function performs an AES single-block encryption or
139 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000140 *
Rose Zadik7f441272018-01-22 11:48:23 +0000141 * It performs the operation defined in the \p mode parameter
142 * (encrypt or decrypt), on the input data buffer defined in
143 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000144 *
Rose Zadik7f441272018-01-22 11:48:23 +0000145 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
146 * mbedtls_aes_setkey_dec() must be called before the first
147 * call to this API with the same context.
148 *
149 * \param ctx The AES context to use for encryption or decryption.
150 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
151 * #MBEDTLS_AES_DECRYPT.
152 * \param input The 16-Byte buffer holding the input data.
153 * \param output The 16-Byte buffer holding the output data.
154
155 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000158 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000159 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000160 unsigned char output[16] );
161
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000163/**
Rose Zadik7f441272018-01-22 11:48:23 +0000164 * \brief This function performs an AES-CBC encryption or decryption operation
165 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000166 *
Rose Zadik7f441272018-01-22 11:48:23 +0000167 * It performs the operation defined in the \p mode
168 * parameter (encrypt/decrypt), on the input data buffer defined in
169 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000170 *
Rose Zadik7f441272018-01-22 11:48:23 +0000171 * It can be called as many times as needed, until all the input
172 * data is processed. mbedtls_aes_init(), and either
173 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
174 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000175 *
Rose Zadik7f441272018-01-22 11:48:23 +0000176 * \note This function operates on aligned blocks, that is, the input size
177 * must be a multiple of the AES block size of 16 Bytes.
178 *
179 * \note Upon exit, the content of the IV is updated so that you can
180 * call the same function again on the next
181 * block(s) of data and get the same result as if it was
182 * encrypted in one call. This allows a "streaming" usage.
183 * If you need to retain the contents of the IV, you should
184 * either save it manually or use the cipher module instead.
185 *
186 *
187 * \param ctx The AES context to use for encryption or decryption.
188 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
189 * #MBEDTLS_AES_DECRYPT.
190 * \param length The length of the input data in Bytes. This must be a
191 * multiple of the block size (16 Bytes).
192 * \param iv Initialization vector (updated after use).
193 * \param input The buffer holding the input data.
194 * \param output The buffer holding the output data.
195 *
196 * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
197 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000198 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000200 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000201 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000202 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000203 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000204 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000206
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000208/**
Rose Zadik7f441272018-01-22 11:48:23 +0000209 * \brief This function performs an AES-CFB128 encryption or decryption
210 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000211 *
Rose Zadik7f441272018-01-22 11:48:23 +0000212 * It performs the operation defined in the \p mode
213 * parameter (encrypt or decrypt), on the input data buffer
214 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000215 *
Rose Zadik7f441272018-01-22 11:48:23 +0000216 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
217 * regardless of whether you are performing an encryption or decryption
218 * operation, that is, regardless of the \p mode parameter. This is
219 * because CFB mode uses the same key schedule for encryption and
220 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000221 *
Rose Zadik7f441272018-01-22 11:48:23 +0000222 * \note Upon exit, the content of the IV is updated so that you can
223 * call the same function again on the next
224 * block(s) of data and get the same result as if it was
225 * encrypted in one call. This allows a "streaming" usage.
226 * If you need to retain the contents of the
227 * IV, you must either save it manually or use the cipher
228 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000229 *
Rose Zadik7f441272018-01-22 11:48:23 +0000230 *
231 * \param ctx The AES context to use for encryption or decryption.
232 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
233 * #MBEDTLS_AES_DECRYPT.
234 * \param length The length of the input data.
235 * \param iv_off The offset in IV (updated after use).
236 * \param iv The initialization vector (updated after use).
237 * \param input The buffer holding the input data.
238 * \param output The buffer holding the output data.
239 *
240 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000241 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000243 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000244 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000245 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000246 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000247 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 unsigned char *output );
249
Paul Bakker9a736322012-11-14 12:39:52 +0000250/**
Rose Zadik7f441272018-01-22 11:48:23 +0000251 * \brief This function performs an AES-CFB8 encryption or decryption
252 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100253 *
Rose Zadik7f441272018-01-22 11:48:23 +0000254 * It performs the operation defined in the \p mode
255 * parameter (encrypt/decrypt), on the input data buffer defined
256 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100257 *
Rose Zadik7f441272018-01-22 11:48:23 +0000258 * Due to the nature of CFB, you must use the same key schedule for
259 * both encryption and decryption operations. Therefore, you must
260 * use the context initialized with mbedtls_aes_setkey_enc() for
261 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000262 *
Rose Zadik7f441272018-01-22 11:48:23 +0000263 * \note Upon exit, the content of the IV is updated so that you can
264 * call the same function again on the next
265 * block(s) of data and get the same result as if it was
266 * encrypted in one call. This allows a "streaming" usage.
267 * If you need to retain the contents of the
268 * IV, you should either save it manually or use the cipher
269 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100270 *
Rose Zadik7f441272018-01-22 11:48:23 +0000271 *
272 * \param ctx The AES context to use for encryption or decryption.
273 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
274 * #MBEDTLS_AES_DECRYPT
275 * \param length The length of the input data.
276 * \param iv The initialization vector (updated after use).
277 * \param input The buffer holding the input data.
278 * \param output The buffer holding the output data.
279 *
280 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100281 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100283 int mode,
284 size_t length,
285 unsigned char iv[16],
286 const unsigned char *input,
287 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200288#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100289
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100291/**
Rose Zadik7f441272018-01-22 11:48:23 +0000292 * \brief This function performs an AES-CTR encryption or decryption
293 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000294 *
Rose Zadik7f441272018-01-22 11:48:23 +0000295 * This function performs the operation defined in the \p mode
296 * parameter (encrypt/decrypt), on the input data buffer
297 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000298 *
Rose Zadik7f441272018-01-22 11:48:23 +0000299 * Due to the nature of CTR, you must use the same key schedule
300 * for both encryption and decryption operations. Therefore, you
301 * must use the context initialized with mbedtls_aes_setkey_enc()
302 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000303 *
Rose Zadik7f441272018-01-22 11:48:23 +0000304 * \warning You must keep the maximum use of your counter in mind.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000305 *
Rose Zadik7f441272018-01-22 11:48:23 +0000306 * \param ctx The AES context to use for encryption or decryption.
307 * \param length The length of the input data.
308 * \param nc_off The offset in the current \p stream_block, for
309 * resuming within the current cipher stream. The
310 * offset pointer should be 0 at the start of a stream.
311 * \param nonce_counter The 128-bit nonce and counter.
312 * \param stream_block The saved stream block for resuming. This is
313 * overwritten by the function.
314 * \param input The buffer holding the input data.
315 * \param output The buffer holding the output data.
316 *
317 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000318 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000320 size_t length,
321 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000322 unsigned char nonce_counter[16],
323 unsigned char stream_block[16],
324 const unsigned char *input,
325 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200327
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200328/**
Rose Zadik7f441272018-01-22 11:48:23 +0000329 * \brief Internal AES block encryption function. This is only
330 * exposed to allow overriding it using
331 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200332 *
Rose Zadik7f441272018-01-22 11:48:23 +0000333 * \param ctx The AES context to use for encryption.
334 * \param input The plaintext block.
335 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000336 *
Rose Zadik7f441272018-01-22 11:48:23 +0000337 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200338 */
Andres AGf5bf7182017-03-03 14:09:56 +0000339int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
340 const unsigned char input[16],
341 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200342
343/**
Rose Zadik7f441272018-01-22 11:48:23 +0000344 * \brief Internal AES block decryption function. This is only
345 * exposed to allow overriding it using see
346 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200347 *
Rose Zadik7f441272018-01-22 11:48:23 +0000348 * \param ctx The AES context to use for decryption.
349 * \param input The ciphertext block.
350 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000351 *
Rose Zadik7f441272018-01-22 11:48:23 +0000352 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200353 */
Andres AGf5bf7182017-03-03 14:09:56 +0000354int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
355 const unsigned char input[16],
356 unsigned char output[16] );
357
358#if !defined(MBEDTLS_DEPRECATED_REMOVED)
359#if defined(MBEDTLS_DEPRECATED_WARNING)
360#define MBEDTLS_DEPRECATED __attribute__((deprecated))
361#else
362#define MBEDTLS_DEPRECATED
363#endif
364/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100365 * \brief Deprecated internal AES block encryption function
366 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000367 *
Rose Zadik7f441272018-01-22 11:48:23 +0000368 * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000369 *
Rose Zadik7f441272018-01-22 11:48:23 +0000370 * \param ctx The AES context to use for encryption.
371 * \param input Plaintext block.
372 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000373 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100374MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
375 const unsigned char input[16],
376 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000377
378/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100379 * \brief Deprecated internal AES block decryption function
380 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000381 *
Rose Zadik7f441272018-01-22 11:48:23 +0000382 * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000383 *
Rose Zadik7f441272018-01-22 11:48:23 +0000384 * \param ctx The AES context to use for decryption.
385 * \param input Ciphertext block.
386 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000387 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100388MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
389 const unsigned char input[16],
390 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000391
392#undef MBEDTLS_DEPRECATED
393#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200394
Paul Bakker90995b52013-06-24 19:20:35 +0200395#ifdef __cplusplus
396}
397#endif
398
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399#else /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200400#include "aes_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200401#endif /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200402
403#ifdef __cplusplus
404extern "C" {
405#endif
406
Paul Bakker5121ce52009-01-03 21:22:43 +0000407/**
Rose Zadik7f441272018-01-22 11:48:23 +0000408 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000409 *
Rose Zadik7f441272018-01-22 11:48:23 +0000410 * \return \c 0 on success, or \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000411 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200412int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000413
414#ifdef __cplusplus
415}
416#endif
417
418#endif /* aes.h */