blob: 4c0429d4502254b992f2cd3fa422e6aef80ab9b6 [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
Paul Bakker407a0da2013-06-27 14:29:21 +020065#ifdef __cplusplus
66extern "C" {
67#endif
68
Ron Eldorb2aacec2017-05-18 16:53:08 +030069#if !defined(MBEDTLS_AES_ALT)
70// Regular implementation
71//
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
Ron Eldorb2aacec2017-05-18 16:53:08 +030091#else /* MBEDTLS_AES_ALT */
92#include "aes_alt.h"
93#endif /* MBEDTLS_AES_ALT */
94
Paul Bakker5121ce52009-01-03 21:22:43 +000095/**
Rose Zadik7f441272018-01-22 11:48:23 +000096 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020097 *
Rose Zadik7f441272018-01-22 11:48:23 +000098 * It must be the first API called before using
99 * the context.
100 *
101 * \param ctx The AES context to initialize.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200102 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200104
105/**
Rose Zadik7f441272018-01-22 11:48:23 +0000106 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200107 *
Rose Zadik7f441272018-01-22 11:48:23 +0000108 * \param ctx The AES context to clear.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200109 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200111
112/**
Rose Zadik7f441272018-01-22 11:48:23 +0000113 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 *
Rose Zadik7f441272018-01-22 11:48:23 +0000115 * \param ctx The AES context to which the key should be bound.
116 * \param key The encryption key.
117 * \param keybits The size of data passed in bits. Valid options are:
118 * <ul><li>128 bits</li>
119 * <li>192 bits</li>
120 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000121 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100122 * \return \c 0 on success.
Rose Zadik819d13d2018-04-16 09:35:15 +0100123 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200126 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000127
128/**
Rose Zadik7f441272018-01-22 11:48:23 +0000129 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 *
Rose Zadik7f441272018-01-22 11:48:23 +0000131 * \param ctx The AES context to which the key should be bound.
132 * \param key The decryption key.
133 * \param keybits The size of data passed. Valid options are:
134 * <ul><li>128 bits</li>
135 * <li>192 bits</li>
136 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000137 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100138 * \return \c 0 on success.
139 * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000140 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200142 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000143
144/**
Rose Zadik7f441272018-01-22 11:48:23 +0000145 * \brief This function performs an AES single-block encryption or
146 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000147 *
Rose Zadik7f441272018-01-22 11:48:23 +0000148 * It performs the operation defined in the \p mode parameter
149 * (encrypt or decrypt), on the input data buffer defined in
150 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000151 *
Rose Zadik7f441272018-01-22 11:48:23 +0000152 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
153 * mbedtls_aes_setkey_dec() must be called before the first
154 * call to this API with the same context.
155 *
156 * \param ctx The AES context to use for encryption or decryption.
157 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
158 * #MBEDTLS_AES_DECRYPT.
159 * \param input The 16-Byte buffer holding the input data.
160 * \param output The 16-Byte buffer holding the output data.
161
162 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000165 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000166 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000167 unsigned char output[16] );
168
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000170/**
Rose Zadik7f441272018-01-22 11:48:23 +0000171 * \brief This function performs an AES-CBC encryption or decryption operation
172 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000173 *
Rose Zadik7f441272018-01-22 11:48:23 +0000174 * It performs the operation defined in the \p mode
175 * parameter (encrypt/decrypt), on the input data buffer defined in
176 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000177 *
Rose Zadik7f441272018-01-22 11:48:23 +0000178 * It can be called as many times as needed, until all the input
179 * data is processed. mbedtls_aes_init(), and either
180 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
181 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000182 *
Rose Zadik7f441272018-01-22 11:48:23 +0000183 * \note This function operates on aligned blocks, that is, the input size
184 * must be a multiple of the AES block size of 16 Bytes.
185 *
186 * \note Upon exit, the content of the IV is updated so that you can
187 * call the same function again on the next
188 * block(s) of data and get the same result as if it was
189 * encrypted in one call. This allows a "streaming" usage.
190 * If you need to retain the contents of the IV, you should
191 * either save it manually or use the cipher module instead.
192 *
193 *
194 * \param ctx The AES context to use for encryption or decryption.
195 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
196 * #MBEDTLS_AES_DECRYPT.
197 * \param length The length of the input data in Bytes. This must be a
198 * multiple of the block size (16 Bytes).
199 * \param iv Initialization vector (updated after use).
200 * \param input The buffer holding the input data.
201 * \param output The buffer holding the output data.
202 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100203 * \return \c 0 on success.
204 * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
Rose Zadik7f441272018-01-22 11:48:23 +0000205 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000208 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000209 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000210 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000211 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000212 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000214
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000216/**
Rose Zadik7f441272018-01-22 11:48:23 +0000217 * \brief This function performs an AES-CFB128 encryption or decryption
218 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000219 *
Rose Zadik7f441272018-01-22 11:48:23 +0000220 * It performs the operation defined in the \p mode
221 * parameter (encrypt or decrypt), on the input data buffer
222 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000223 *
Rose Zadik7f441272018-01-22 11:48:23 +0000224 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
225 * regardless of whether you are performing an encryption or decryption
226 * operation, that is, regardless of the \p mode parameter. This is
227 * because CFB mode uses the same key schedule for encryption and
228 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000229 *
Rose Zadik7f441272018-01-22 11:48:23 +0000230 * \note Upon exit, the content of the IV is updated so that you can
231 * call the same function again on the next
232 * block(s) of data and get the same result as if it was
233 * encrypted in one call. This allows a "streaming" usage.
234 * If you need to retain the contents of the
235 * IV, you must either save it manually or use the cipher
236 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000237 *
Rose Zadik7f441272018-01-22 11:48:23 +0000238 *
239 * \param ctx The AES context to use for encryption or decryption.
240 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
241 * #MBEDTLS_AES_DECRYPT.
242 * \param length The length of the input data.
243 * \param iv_off The offset in IV (updated after use).
244 * \param iv The initialization vector (updated after use).
245 * \param input The buffer holding the input data.
246 * \param output The buffer holding the output data.
247 *
248 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000249 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200250int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000251 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000252 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000253 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000254 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000255 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000256 unsigned char *output );
257
Paul Bakker9a736322012-11-14 12:39:52 +0000258/**
Rose Zadik7f441272018-01-22 11:48:23 +0000259 * \brief This function performs an AES-CFB8 encryption or decryption
260 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100261 *
Rose Zadik7f441272018-01-22 11:48:23 +0000262 * It performs the operation defined in the \p mode
263 * parameter (encrypt/decrypt), on the input data buffer defined
264 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100265 *
Rose Zadik7f441272018-01-22 11:48:23 +0000266 * Due to the nature of CFB, you must use the same key schedule for
267 * both encryption and decryption operations. Therefore, you must
268 * use the context initialized with mbedtls_aes_setkey_enc() for
269 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000270 *
Rose Zadik7f441272018-01-22 11:48:23 +0000271 * \note Upon exit, the content of the IV is updated so that you can
272 * call the same function again on the next
273 * block(s) of data and get the same result as if it was
274 * encrypted in one call. This allows a "streaming" usage.
275 * If you need to retain the contents of the
276 * IV, you should either save it manually or use the cipher
277 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100278 *
Rose Zadik7f441272018-01-22 11:48:23 +0000279 *
280 * \param ctx The AES context to use for encryption or decryption.
281 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
282 * #MBEDTLS_AES_DECRYPT
283 * \param length The length of the input data.
284 * \param iv The initialization vector (updated after use).
285 * \param input The buffer holding the input data.
286 * \param output The buffer holding the output data.
287 *
288 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100289 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100291 int mode,
292 size_t length,
293 unsigned char iv[16],
294 const unsigned char *input,
295 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100297
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100299/**
Rose Zadik7f441272018-01-22 11:48:23 +0000300 * \brief This function performs an AES-CTR encryption or decryption
301 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000302 *
Rose Zadik7f441272018-01-22 11:48:23 +0000303 * This function performs the operation defined in the \p mode
304 * parameter (encrypt/decrypt), on the input data buffer
305 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000306 *
Rose Zadik7f441272018-01-22 11:48:23 +0000307 * Due to the nature of CTR, you must use the same key schedule
308 * for both encryption and decryption operations. Therefore, you
309 * must use the context initialized with mbedtls_aes_setkey_enc()
310 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000311 *
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100312 * \warning You must never reuse a nonce value with the same key. Doing so
313 * would void the encryption for the two messages encrypted with
314 * the same nonce and key.
315 *
316 * There are two common strategies for managing nonces with CTR:
317 *
318 * 1. Use a counter starting at 0 or a random value. With this
319 * strategy, this function will increment the counter for you, so
320 * you only need to preserve the \p nonce_counter buffer between
321 * calls. With this strategy, you must not encrypt more than
322 * 2**128 blocks of data.
323 * 2. Use a randomly-generated \p nonce_counter for each call.
324 * With this strategy, you need to ensure the nonce is generated
325 * in an unbiased way and you must not encrypt more than 2**64
Manuel Pégourié-Gonnardf6b787c2018-03-01 13:48:21 +0100326 * blocks of data.
Manuel Pégourié-Gonnard22997b72018-02-28 12:29:41 +0100327 *
328 * Note that for both stategies, the limit is in number of blocks
329 * and that an AES block is 16 bytes.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000330 *
Rose Zadik7f441272018-01-22 11:48:23 +0000331 * \param ctx The AES context to use for encryption or decryption.
332 * \param length The length of the input data.
333 * \param nc_off The offset in the current \p stream_block, for
334 * resuming within the current cipher stream. The
335 * offset pointer should be 0 at the start of a stream.
336 * \param nonce_counter The 128-bit nonce and counter.
337 * \param stream_block The saved stream block for resuming. This is
338 * overwritten by the function.
339 * \param input The buffer holding the input data.
340 * \param output The buffer holding the output data.
341 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100342 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000343 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000345 size_t length,
346 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000347 unsigned char nonce_counter[16],
348 unsigned char stream_block[16],
349 const unsigned char *input,
350 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200352
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200353/**
Rose Zadik7f441272018-01-22 11:48:23 +0000354 * \brief Internal AES block encryption function. This is only
355 * exposed to allow overriding it using
356 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200357 *
Rose Zadik7f441272018-01-22 11:48:23 +0000358 * \param ctx The AES context to use for encryption.
359 * \param input The plaintext block.
360 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000361 *
Rose Zadik7f441272018-01-22 11:48:23 +0000362 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200363 */
Andres AGf5bf7182017-03-03 14:09:56 +0000364int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
365 const unsigned char input[16],
366 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200367
368/**
Rose Zadik7f441272018-01-22 11:48:23 +0000369 * \brief Internal AES block decryption function. This is only
370 * exposed to allow overriding it using see
371 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200372 *
Rose Zadik7f441272018-01-22 11:48:23 +0000373 * \param ctx The AES context to use for decryption.
374 * \param input The ciphertext block.
375 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000376 *
Rose Zadik7f441272018-01-22 11:48:23 +0000377 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200378 */
Andres AGf5bf7182017-03-03 14:09:56 +0000379int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
380 const unsigned char input[16],
381 unsigned char output[16] );
382
383#if !defined(MBEDTLS_DEPRECATED_REMOVED)
384#if defined(MBEDTLS_DEPRECATED_WARNING)
385#define MBEDTLS_DEPRECATED __attribute__((deprecated))
386#else
387#define MBEDTLS_DEPRECATED
388#endif
389/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100390 * \brief Deprecated internal AES block encryption function
391 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000392 *
Rose Zadik7f441272018-01-22 11:48:23 +0000393 * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000394 *
Rose Zadik7f441272018-01-22 11:48:23 +0000395 * \param ctx The AES context to use for encryption.
396 * \param input Plaintext block.
397 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000398 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100399MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
400 const unsigned char input[16],
401 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000402
403/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100404 * \brief Deprecated internal AES block decryption function
405 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000406 *
Rose Zadik7f441272018-01-22 11:48:23 +0000407 * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000408 *
Rose Zadik7f441272018-01-22 11:48:23 +0000409 * \param ctx The AES context to use for decryption.
410 * \param input Ciphertext block.
411 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000412 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100413MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
414 const unsigned char input[16],
415 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000416
417#undef MBEDTLS_DEPRECATED
418#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200419
Paul Bakker5121ce52009-01-03 21:22:43 +0000420/**
Rose Zadik7f441272018-01-22 11:48:23 +0000421 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000422 *
Rose Zadik5ad7aea2018-03-26 12:00:09 +0100423 * \return \c 0 on success.
424 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000425 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000427
428#ifdef __cplusplus
429}
430#endif
431
432#endif /* aes.h */