blob: 8fa80ef4f344ca33f52b2e5b8679a968625f8e0c [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 */
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020015/*
16 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
17 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
18 *
19 * This file is provided under the Apache License 2.0, or the
20 * GNU General Public License v2.0 or later.
21 *
22 * **********
23 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020024 *
25 * Licensed under the Apache License, Version 2.0 (the "License"); you may
26 * not use this file except in compliance with the License.
27 * You may obtain a copy of the License at
28 *
29 * http://www.apache.org/licenses/LICENSE-2.0
30 *
31 * Unless required by applicable law or agreed to in writing, software
32 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
33 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 * See the License for the specific language governing permissions and
35 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000036 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020037 * **********
38 *
39 * **********
40 * GNU General Public License v2.0 or later:
41 *
42 * This program is free software; you can redistribute it and/or modify
43 * it under the terms of the GNU General Public License as published by
44 * the Free Software Foundation; either version 2 of the License, or
45 * (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License along
53 * with this program; if not, write to the Free Software Foundation, Inc.,
54 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
55 *
56 * **********
57 *
Rose Zadik7f441272018-01-22 11:48:23 +000058 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000059 */
Rose Zadik7f441272018-01-22 11:48:23 +000060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#ifndef MBEDTLS_AES_H
62#define MBEDTLS_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +000063
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020065#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020066#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020068#endif
Paul Bakker90995b52013-06-24 19:20:35 +020069
Rich Evans00ab4702015-02-06 13:43:58 +000070#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020071#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000072
Manuel Pégourié-Gonnard5b685652013-12-18 11:45:21 +010073/* padlock.c and aesni.c rely on these values! */
Rose Zadik7f441272018-01-22 11:48:23 +000074#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
75#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
Paul Bakker5121ce52009-01-03 21:22:43 +000076
Andres Amaya Garciac5380642017-11-28 19:57:51 +000077/* Error codes in range 0x0020-0x0022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
79#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
Paul Bakker2b222c82009-07-27 21:03:45 +000080
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010081/* Error codes in range 0x0023-0x0025 */
Rose Zadik7f441272018-01-22 11:48:23 +000082#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010083#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000084
Andres AGf5bf7182017-03-03 14:09:56 +000085#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
86 !defined(inline) && !defined(__cplusplus)
87#define inline __inline
88#endif
89
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090#if !defined(MBEDTLS_AES_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020091// Regular implementation
92//
93
Paul Bakker407a0da2013-06-27 14:29:21 +020094#ifdef __cplusplus
95extern "C" {
96#endif
97
Paul Bakker5121ce52009-01-03 21:22:43 +000098/**
Rose Zadik7f441272018-01-22 11:48:23 +000099 * \brief The AES context-type definition.
Paul Bakker5121ce52009-01-03 21:22:43 +0000100 */
101typedef struct
102{
Rose Zadik7f441272018-01-22 11:48:23 +0000103 int nr; /*!< The number of rounds. */
104 uint32_t *rk; /*!< AES round keys. */
105 uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
106 hold 32 extra Bytes, which can be used for
107 one of the following purposes:
108 <ul><li>Alignment if VIA padlock is
109 used.</li>
110 <li>Simplifying key expansion in the 256-bit
111 case by generating an extra round key.
112 </li></ul> */
Paul Bakker5121ce52009-01-03 21:22:43 +0000113}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114mbedtls_aes_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000115
Paul Bakker5121ce52009-01-03 21:22:43 +0000116/**
Rose Zadik7f441272018-01-22 11:48:23 +0000117 * \brief This function initializes the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200118 *
Rose Zadik7f441272018-01-22 11:48:23 +0000119 * It must be the first API called before using
120 * the context.
121 *
122 * \param ctx The AES context to initialize.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200123 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124void mbedtls_aes_init( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200125
126/**
Rose Zadik7f441272018-01-22 11:48:23 +0000127 * \brief This function releases and clears the specified AES context.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200128 *
Rose Zadik7f441272018-01-22 11:48:23 +0000129 * \param ctx The AES context to clear.
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200130 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131void mbedtls_aes_free( mbedtls_aes_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200132
133/**
Rose Zadik7f441272018-01-22 11:48:23 +0000134 * \brief This function sets the encryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000135 *
Rose Zadik7f441272018-01-22 11:48:23 +0000136 * \param ctx The AES context to which the key should be bound.
137 * \param key The encryption key.
138 * \param keybits The size of data passed in bits. Valid options are:
139 * <ul><li>128 bits</li>
140 * <li>192 bits</li>
141 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000142 *
Rose Zadik7f441272018-01-22 11:48:23 +0000143 * \return \c 0 on success or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
144 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000145 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200147 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000148
149/**
Rose Zadik7f441272018-01-22 11:48:23 +0000150 * \brief This function sets the decryption key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 *
Rose Zadik7f441272018-01-22 11:48:23 +0000152 * \param ctx The AES context to which the key should be bound.
153 * \param key The decryption key.
154 * \param keybits The size of data passed. Valid options are:
155 * <ul><li>128 bits</li>
156 * <li>192 bits</li>
157 * <li>256 bits</li></ul>
Paul Bakker2b222c82009-07-27 21:03:45 +0000158 *
Rose Zadik7f441272018-01-22 11:48:23 +0000159 * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000160 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200162 unsigned int keybits );
Paul Bakker5121ce52009-01-03 21:22:43 +0000163
164/**
Rose Zadik7f441272018-01-22 11:48:23 +0000165 * \brief This function performs an AES single-block encryption or
166 * decryption operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000167 *
Rose Zadik7f441272018-01-22 11:48:23 +0000168 * It performs the operation defined in the \p mode parameter
169 * (encrypt or decrypt), on the input data buffer defined in
170 * the \p input parameter.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000171 *
Rose Zadik7f441272018-01-22 11:48:23 +0000172 * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
173 * mbedtls_aes_setkey_dec() must be called before the first
174 * call to this API with the same context.
175 *
176 * \param ctx The AES context to use for encryption or decryption.
177 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
178 * #MBEDTLS_AES_DECRYPT.
179 * \param input The 16-Byte buffer holding the input data.
180 * \param output The 16-Byte buffer holding the output data.
181
182 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000183 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000185 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000186 const unsigned char input[16],
Paul Bakker5121ce52009-01-03 21:22:43 +0000187 unsigned char output[16] );
188
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker5121ce52009-01-03 21:22:43 +0000190/**
Rose Zadik7f441272018-01-22 11:48:23 +0000191 * \brief This function performs an AES-CBC encryption or decryption operation
192 * on full blocks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000193 *
Rose Zadik7f441272018-01-22 11:48:23 +0000194 * It performs the operation defined in the \p mode
195 * parameter (encrypt/decrypt), on the input data buffer defined in
196 * the \p input parameter.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000197 *
Rose Zadik7f441272018-01-22 11:48:23 +0000198 * It can be called as many times as needed, until all the input
199 * data is processed. mbedtls_aes_init(), and either
200 * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
201 * before the first call to this API with the same context.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000202 *
Rose Zadik7f441272018-01-22 11:48:23 +0000203 * \note This function operates on aligned blocks, that is, the input size
204 * must be a multiple of the AES block size of 16 Bytes.
205 *
206 * \note Upon exit, the content of the IV is updated so that you can
207 * call the same function again on the next
208 * block(s) of data and get the same result as if it was
209 * encrypted in one call. This allows a "streaming" usage.
210 * If you need to retain the contents of the IV, you should
211 * either save it manually or use the cipher module instead.
212 *
213 *
214 * \param ctx The AES context to use for encryption or decryption.
215 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
216 * #MBEDTLS_AES_DECRYPT.
217 * \param length The length of the input data in Bytes. This must be a
218 * multiple of the block size (16 Bytes).
219 * \param iv Initialization vector (updated after use).
220 * \param input The buffer holding the input data.
221 * \param output The buffer holding the output data.
222 *
223 * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
224 * on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000225 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000227 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000228 size_t length,
Paul Bakker5121ce52009-01-03 21:22:43 +0000229 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000230 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000231 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker5121ce52009-01-03 21:22:43 +0000233
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker5121ce52009-01-03 21:22:43 +0000235/**
Rose Zadik7f441272018-01-22 11:48:23 +0000236 * \brief This function performs an AES-CFB128 encryption or decryption
237 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000238 *
Rose Zadik7f441272018-01-22 11:48:23 +0000239 * It performs the operation defined in the \p mode
240 * parameter (encrypt or decrypt), on the input data buffer
241 * defined in the \p input parameter.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000242 *
Rose Zadik7f441272018-01-22 11:48:23 +0000243 * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
244 * regardless of whether you are performing an encryption or decryption
245 * operation, that is, regardless of the \p mode parameter. This is
246 * because CFB mode uses the same key schedule for encryption and
247 * decryption.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000248 *
Rose Zadik7f441272018-01-22 11:48:23 +0000249 * \note Upon exit, the content of the IV is updated so that you can
250 * call the same function again on the next
251 * block(s) of data and get the same result as if it was
252 * encrypted in one call. This allows a "streaming" usage.
253 * If you need to retain the contents of the
254 * IV, you must either save it manually or use the cipher
255 * module instead.
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000256 *
Rose Zadik7f441272018-01-22 11:48:23 +0000257 *
258 * \param ctx The AES context to use for encryption or decryption.
259 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
260 * #MBEDTLS_AES_DECRYPT.
261 * \param length The length of the input data.
262 * \param iv_off The offset in IV (updated after use).
263 * \param iv The initialization vector (updated after use).
264 * \param input The buffer holding the input data.
265 * \param output The buffer holding the output data.
266 *
267 * \return \c 0 on success.
Paul Bakker5121ce52009-01-03 21:22:43 +0000268 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
Paul Bakker5121ce52009-01-03 21:22:43 +0000270 int mode,
Paul Bakker23986e52011-04-24 08:57:21 +0000271 size_t length,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000272 size_t *iv_off,
Paul Bakker5121ce52009-01-03 21:22:43 +0000273 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000274 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000275 unsigned char *output );
276
Paul Bakker9a736322012-11-14 12:39:52 +0000277/**
Rose Zadik7f441272018-01-22 11:48:23 +0000278 * \brief This function performs an AES-CFB8 encryption or decryption
279 * operation.
Paul Bakker556efba2014-01-24 15:38:12 +0100280 *
Rose Zadik7f441272018-01-22 11:48:23 +0000281 * It performs the operation defined in the \p mode
282 * parameter (encrypt/decrypt), on the input data buffer defined
283 * in the \p input parameter.
Paul Bakker556efba2014-01-24 15:38:12 +0100284 *
Rose Zadik7f441272018-01-22 11:48:23 +0000285 * Due to the nature of CFB, you must use the same key schedule for
286 * both encryption and decryption operations. Therefore, you must
287 * use the context initialized with mbedtls_aes_setkey_enc() for
288 * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Manuel Pégourié-Gonnard2be147a2015-01-23 16:19:47 +0000289 *
Rose Zadik7f441272018-01-22 11:48:23 +0000290 * \note Upon exit, the content of the IV is updated so that you can
291 * call the same function again on the next
292 * block(s) of data and get the same result as if it was
293 * encrypted in one call. This allows a "streaming" usage.
294 * If you need to retain the contents of the
295 * IV, you should either save it manually or use the cipher
296 * module instead.
Paul Bakker556efba2014-01-24 15:38:12 +0100297 *
Rose Zadik7f441272018-01-22 11:48:23 +0000298 *
299 * \param ctx The AES context to use for encryption or decryption.
300 * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
301 * #MBEDTLS_AES_DECRYPT
302 * \param length The length of the input data.
303 * \param iv The initialization vector (updated after use).
304 * \param input The buffer holding the input data.
305 * \param output The buffer holding the output data.
306 *
307 * \return \c 0 on success.
Paul Bakker556efba2014-01-24 15:38:12 +0100308 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
Paul Bakker556efba2014-01-24 15:38:12 +0100310 int mode,
311 size_t length,
312 unsigned char iv[16],
313 const unsigned char *input,
314 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#endif /*MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker556efba2014-01-24 15:38:12 +0100316
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker556efba2014-01-24 15:38:12 +0100318/**
Rose Zadik7f441272018-01-22 11:48:23 +0000319 * \brief This function performs an AES-CTR encryption or decryption
320 * operation.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000321 *
Rose Zadik7f441272018-01-22 11:48:23 +0000322 * This function performs the operation defined in the \p mode
323 * parameter (encrypt/decrypt), on the input data buffer
324 * defined in the \p input parameter.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000325 *
Rose Zadik7f441272018-01-22 11:48:23 +0000326 * Due to the nature of CTR, you must use the same key schedule
327 * for both encryption and decryption operations. Therefore, you
328 * must use the context initialized with mbedtls_aes_setkey_enc()
329 * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
Paul Bakkerca6f3e22011-10-06 13:11:08 +0000330 *
Rose Zadik7f441272018-01-22 11:48:23 +0000331 * \warning You must keep the maximum use of your counter in mind.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000332 *
Rose Zadik7f441272018-01-22 11:48:23 +0000333 * \param ctx The AES context to use for encryption or decryption.
334 * \param length The length of the input data.
335 * \param nc_off The offset in the current \p stream_block, for
336 * resuming within the current cipher stream. The
337 * offset pointer should be 0 at the start of a stream.
338 * \param nonce_counter The 128-bit nonce and counter.
339 * \param stream_block The saved stream block for resuming. This is
340 * overwritten by the function.
341 * \param input The buffer holding the input data.
342 * \param output The buffer holding the output data.
343 *
344 * \return \c 0 on success.
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000345 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200346int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
Paul Bakker1ef71df2011-06-09 14:14:58 +0000347 size_t length,
348 size_t *nc_off,
Paul Bakkerb6ecaf52011-04-19 14:29:23 +0000349 unsigned char nonce_counter[16],
350 unsigned char stream_block[16],
351 const unsigned char *input,
352 unsigned char *output );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200353#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker90995b52013-06-24 19:20:35 +0200354
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200355/**
Rose Zadik7f441272018-01-22 11:48:23 +0000356 * \brief Internal AES block encryption function. This is only
357 * exposed to allow overriding it using
358 * \c MBEDTLS_AES_ENCRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200359 *
Rose Zadik7f441272018-01-22 11:48:23 +0000360 * \param ctx The AES context to use for encryption.
361 * \param input The plaintext block.
362 * \param output The output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000363 *
Rose Zadik7f441272018-01-22 11:48:23 +0000364 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200365 */
Andres AGf5bf7182017-03-03 14:09:56 +0000366int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
367 const unsigned char input[16],
368 unsigned char output[16] );
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200369
370/**
Rose Zadik7f441272018-01-22 11:48:23 +0000371 * \brief Internal AES block decryption function. This is only
372 * exposed to allow overriding it using see
373 * \c MBEDTLS_AES_DECRYPT_ALT.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200374 *
Rose Zadik7f441272018-01-22 11:48:23 +0000375 * \param ctx The AES context to use for decryption.
376 * \param input The ciphertext block.
377 * \param output The output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000378 *
Rose Zadik7f441272018-01-22 11:48:23 +0000379 * \return \c 0 on success.
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200380 */
Andres AGf5bf7182017-03-03 14:09:56 +0000381int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
382 const unsigned char input[16],
383 unsigned char output[16] );
384
385#if !defined(MBEDTLS_DEPRECATED_REMOVED)
386#if defined(MBEDTLS_DEPRECATED_WARNING)
387#define MBEDTLS_DEPRECATED __attribute__((deprecated))
388#else
389#define MBEDTLS_DEPRECATED
390#endif
391/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100392 * \brief Deprecated internal AES block encryption function
393 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000394 *
Rose Zadik7f441272018-01-22 11:48:23 +0000395 * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000396 *
Rose Zadik7f441272018-01-22 11:48:23 +0000397 * \param ctx The AES context to use for encryption.
398 * \param input Plaintext block.
399 * \param output Output (ciphertext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000400 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100401MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
402 const unsigned char input[16],
403 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000404
405/**
Hanno Beckerca1cdb22017-07-20 09:50:59 +0100406 * \brief Deprecated internal AES block decryption function
407 * without return value.
Andres AGf5bf7182017-03-03 14:09:56 +0000408 *
Rose Zadik7f441272018-01-22 11:48:23 +0000409 * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
Andres AGf5bf7182017-03-03 14:09:56 +0000410 *
Rose Zadik7f441272018-01-22 11:48:23 +0000411 * \param ctx The AES context to use for decryption.
412 * \param input Ciphertext block.
413 * \param output Output (plaintext) block.
Andres AGf5bf7182017-03-03 14:09:56 +0000414 */
Hanno Beckerbedc2052017-06-26 12:46:56 +0100415MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
416 const unsigned char input[16],
417 unsigned char output[16] );
Andres AGf5bf7182017-03-03 14:09:56 +0000418
419#undef MBEDTLS_DEPRECATED
420#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Manuel Pégourié-Gonnard31993f22015-05-12 15:41:08 +0200421
Paul Bakker90995b52013-06-24 19:20:35 +0200422#ifdef __cplusplus
423}
424#endif
425
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426#else /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200427#include "aes_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200428#endif /* MBEDTLS_AES_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200429
430#ifdef __cplusplus
431extern "C" {
432#endif
433
Paul Bakker5121ce52009-01-03 21:22:43 +0000434/**
Rose Zadik7f441272018-01-22 11:48:23 +0000435 * \brief Checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +0000436 *
Rose Zadik7f441272018-01-22 11:48:23 +0000437 * \return \c 0 on success, or \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000438 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200439int mbedtls_aes_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000440
441#ifdef __cplusplus
442}
443#endif
444
445#endif /* aes.h */