Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file aes.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | f3b86c1 | 2011-01-27 15:24:17 +0000 | [diff] [blame] | 4 | * \brief AES block cipher |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 8 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 9 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 23 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 24 | #ifndef MBEDTLS_AES_H |
| 25 | #define MBEDTLS_AES_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 27 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 28 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 30 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 31 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 32 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 33 | #include <stddef.h> |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 34 | |
Paul Bakker | fa6a620 | 2013-10-28 18:48:30 +0100 | [diff] [blame] | 35 | #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 36 | #include <basetsd.h> |
| 37 | typedef UINT32 uint32_t; |
| 38 | #else |
| 39 | #include <inttypes.h> |
| 40 | #endif |
| 41 | |
Manuel Pégourié-Gonnard | 5b68565 | 2013-12-18 11:45:21 +0100 | [diff] [blame] | 42 | /* padlock.c and aesni.c rely on these values! */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 43 | #define MBEDTLS_AES_ENCRYPT 1 |
| 44 | #define MBEDTLS_AES_DECRYPT 0 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 45 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 46 | #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */ |
| 47 | #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */ |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 48 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 49 | #if !defined(MBEDTLS_AES_ALT) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 50 | // Regular implementation |
| 51 | // |
| 52 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 53 | #ifdef __cplusplus |
| 54 | extern "C" { |
| 55 | #endif |
| 56 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 57 | /** |
| 58 | * \brief AES context structure |
Manuel Pégourié-Gonnard | 4a5b995 | 2013-12-29 13:50:32 +0100 | [diff] [blame] | 59 | * |
| 60 | * \note buf is able to hold 32 extra bytes, which can be used: |
| 61 | * - for alignment purposes if VIA padlock is used, and/or |
| 62 | * - to simplify key expansion in the 256-bit case by |
| 63 | * generating an extra round key |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 64 | */ |
| 65 | typedef struct |
| 66 | { |
| 67 | int nr; /*!< number of rounds */ |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 68 | uint32_t *rk; /*!< AES round keys */ |
| 69 | uint32_t buf[68]; /*!< unaligned data */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 70 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 71 | mbedtls_aes_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 72 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 73 | /** |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 74 | * \brief Initialize AES context |
| 75 | * |
| 76 | * \param ctx AES context to be initialized |
| 77 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 78 | void mbedtls_aes_init( mbedtls_aes_context *ctx ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * \brief Clear AES context |
| 82 | * |
| 83 | * \param ctx AES context to be cleared |
| 84 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 85 | void mbedtls_aes_free( mbedtls_aes_context *ctx ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 86 | |
| 87 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 88 | * \brief AES key schedule (encryption) |
| 89 | * |
| 90 | * \param ctx AES context to be initialized |
| 91 | * \param key encryption key |
| 92 | * \param keysize must be 128, 192 or 256 |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 93 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 94 | * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 95 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 96 | int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 97 | unsigned int keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * \brief AES key schedule (decryption) |
| 101 | * |
| 102 | * \param ctx AES context to be initialized |
| 103 | * \param key decryption key |
| 104 | * \param keysize must be 128, 192 or 256 |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 105 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 106 | * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 107 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 108 | int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 109 | unsigned int keysize ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * \brief AES-ECB block encryption/decryption |
| 113 | * |
| 114 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 115 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 116 | * \param input 16-byte input block |
| 117 | * \param output 16-byte output block |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 118 | * |
Paul Bakker | 27caa8a | 2010-03-21 15:43:59 +0000 | [diff] [blame] | 119 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 120 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 121 | int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 122 | int mode, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 123 | const unsigned char input[16], |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 124 | unsigned char output[16] ); |
| 125 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 126 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 127 | /** |
| 128 | * \brief AES-CBC buffer encryption/decryption |
Paul Bakker | 4c067eb | 2009-05-17 10:25:19 +0000 | [diff] [blame] | 129 | * Length should be a multiple of the block |
| 130 | * size (16 bytes) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 131 | * |
Manuel Pégourié-Gonnard | 2be147a | 2015-01-23 16:19:47 +0000 | [diff] [blame] | 132 | * \note Upon exit, the content of the IV is updated so that you can |
| 133 | * call the function same function again on the following |
| 134 | * block(s) of data and get the same result as if it was |
| 135 | * encrypted in one call. This allows a "streaming" usage. |
| 136 | * If on the other hand you need to retain the contents of the |
| 137 | * IV, you should either save it manually or use the cipher |
| 138 | * module instead. |
| 139 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 140 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 141 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 142 | * \param length length of the input data |
| 143 | * \param iv initialization vector (updated after use) |
| 144 | * \param input buffer holding the input data |
| 145 | * \param output buffer holding the output data |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 146 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 147 | * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 148 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 149 | int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 150 | int mode, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 151 | size_t length, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 152 | unsigned char iv[16], |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 153 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 154 | unsigned char *output ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 155 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 156 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 157 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 158 | /** |
Paul Bakker | 4c067eb | 2009-05-17 10:25:19 +0000 | [diff] [blame] | 159 | * \brief AES-CFB128 buffer encryption/decryption. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 160 | * |
Paul Bakker | ca6f3e2 | 2011-10-06 13:11:08 +0000 | [diff] [blame] | 161 | * Note: Due to the nature of CFB you should use the same key schedule for |
| 162 | * both encryption and decryption. So a context initialized with |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 163 | * mbedtls_aes_setkey_enc() for both MBEDTLS_AES_ENCRYPT and MBEDTLS_AES_DECRYPT. |
Paul Bakker | ca6f3e2 | 2011-10-06 13:11:08 +0000 | [diff] [blame] | 164 | * |
Manuel Pégourié-Gonnard | 2be147a | 2015-01-23 16:19:47 +0000 | [diff] [blame] | 165 | * \note Upon exit, the content of the IV is updated so that you can |
| 166 | * call the function same function again on the following |
| 167 | * block(s) of data and get the same result as if it was |
| 168 | * encrypted in one call. This allows a "streaming" usage. |
| 169 | * If on the other hand you need to retain the contents of the |
| 170 | * IV, you should either save it manually or use the cipher |
| 171 | * module instead. |
| 172 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 173 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 174 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 175 | * \param length length of the input data |
| 176 | * \param iv_off offset in IV (updated after use) |
| 177 | * \param iv initialization vector (updated after use) |
| 178 | * \param input buffer holding the input data |
| 179 | * \param output buffer holding the output data |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 180 | * |
Paul Bakker | 27caa8a | 2010-03-21 15:43:59 +0000 | [diff] [blame] | 181 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 182 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 183 | int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 184 | int mode, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 185 | size_t length, |
Paul Bakker | 1ef71df | 2011-06-09 14:14:58 +0000 | [diff] [blame] | 186 | size_t *iv_off, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 187 | unsigned char iv[16], |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 188 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 189 | unsigned char *output ); |
| 190 | |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 191 | /** |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 192 | * \brief AES-CFB8 buffer encryption/decryption. |
| 193 | * |
| 194 | * Note: Due to the nature of CFB you should use the same key schedule for |
| 195 | * both encryption and decryption. So a context initialized with |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 196 | * mbedtls_aes_setkey_enc() for both MBEDTLS_AES_ENCRYPT and MBEDTLS_AES_DECRYPT. |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 197 | * |
Manuel Pégourié-Gonnard | 2be147a | 2015-01-23 16:19:47 +0000 | [diff] [blame] | 198 | * \note Upon exit, the content of the IV is updated so that you can |
| 199 | * call the function same function again on the following |
| 200 | * block(s) of data and get the same result as if it was |
| 201 | * encrypted in one call. This allows a "streaming" usage. |
| 202 | * If on the other hand you need to retain the contents of the |
| 203 | * IV, you should either save it manually or use the cipher |
| 204 | * module instead. |
| 205 | * |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 206 | * \param ctx AES context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 207 | * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 208 | * \param length length of the input data |
| 209 | * \param iv initialization vector (updated after use) |
| 210 | * \param input buffer holding the input data |
| 211 | * \param output buffer holding the output data |
| 212 | * |
| 213 | * \return 0 if successful |
| 214 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 215 | int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 216 | int mode, |
| 217 | size_t length, |
| 218 | unsigned char iv[16], |
| 219 | const unsigned char *input, |
| 220 | unsigned char *output ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 221 | #endif /*MBEDTLS_CIPHER_MODE_CFB */ |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 222 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 223 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Paul Bakker | 556efba | 2014-01-24 15:38:12 +0100 | [diff] [blame] | 224 | /** |
Paul Bakker | b6ecaf5 | 2011-04-19 14:29:23 +0000 | [diff] [blame] | 225 | * \brief AES-CTR buffer encryption/decryption |
| 226 | * |
| 227 | * Warning: You have to keep the maximum use of your counter in mind! |
| 228 | * |
Paul Bakker | ca6f3e2 | 2011-10-06 13:11:08 +0000 | [diff] [blame] | 229 | * Note: Due to the nature of CTR you should use the same key schedule for |
| 230 | * both encryption and decryption. So a context initialized with |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 231 | * mbedtls_aes_setkey_enc() for both MBEDTLS_AES_ENCRYPT and MBEDTLS_AES_DECRYPT. |
Paul Bakker | ca6f3e2 | 2011-10-06 13:11:08 +0000 | [diff] [blame] | 232 | * |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 233 | * \param ctx AES context |
Paul Bakker | b6ecaf5 | 2011-04-19 14:29:23 +0000 | [diff] [blame] | 234 | * \param length The length of the data |
| 235 | * \param nc_off The offset in the current stream_block (for resuming |
| 236 | * within current cipher stream). The offset pointer to |
| 237 | * should be 0 at the start of a stream. |
| 238 | * \param nonce_counter The 128-bit nonce and counter. |
| 239 | * \param stream_block The saved stream-block for resuming. Is overwritten |
| 240 | * by the function. |
| 241 | * \param input The input data stream |
| 242 | * \param output The output data stream |
| 243 | * |
| 244 | * \return 0 if successful |
| 245 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 246 | int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, |
Paul Bakker | 1ef71df | 2011-06-09 14:14:58 +0000 | [diff] [blame] | 247 | size_t length, |
| 248 | size_t *nc_off, |
Paul Bakker | b6ecaf5 | 2011-04-19 14:29:23 +0000 | [diff] [blame] | 249 | unsigned char nonce_counter[16], |
| 250 | unsigned char stream_block[16], |
| 251 | const unsigned char *input, |
| 252 | unsigned char *output ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 253 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 254 | |
| 255 | #ifdef __cplusplus |
| 256 | } |
| 257 | #endif |
| 258 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 259 | #else /* MBEDTLS_AES_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 260 | #include "aes_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 261 | #endif /* MBEDTLS_AES_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 262 | |
| 263 | #ifdef __cplusplus |
| 264 | extern "C" { |
| 265 | #endif |
| 266 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 267 | /** |
| 268 | * \brief Checkup routine |
| 269 | * |
| 270 | * \return 0 if successful, or 1 if the test failed |
| 271 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame^] | 272 | int mbedtls_aes_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 273 | |
| 274 | #ifdef __cplusplus |
| 275 | } |
| 276 | #endif |
| 277 | |
| 278 | #endif /* aes.h */ |