mbed TLS v2.16.1
aes.h
Go to the documentation of this file.
1 
23 /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
24  * SPDX-License-Identifier: GPL-2.0
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 2 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License along
37  * with this program; if not, write to the Free Software Foundation, Inc.,
38  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39  *
40  * This file is part of Mbed TLS (https://tls.mbed.org)
41  */
42 
43 #ifndef MBEDTLS_AES_H
44 #define MBEDTLS_AES_H
45 
46 #if !defined(MBEDTLS_CONFIG_FILE)
47 #include "config.h"
48 #else
49 #include MBEDTLS_CONFIG_FILE
50 #endif
51 
52 #include <stddef.h>
53 #include <stdint.h>
54 
55 /* padlock.c and aesni.c rely on these values! */
56 #define MBEDTLS_AES_ENCRYPT 1
57 #define MBEDTLS_AES_DECRYPT 0
59 /* Error codes in range 0x0020-0x0022 */
60 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
61 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
63 /* Error codes in range 0x0021-0x0025 */
64 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
66 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
67 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
69 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
70 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
72 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
73  !defined(inline) && !defined(__cplusplus)
74 #define inline __inline
75 #endif
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
81 #if !defined(MBEDTLS_AES_ALT)
82 // Regular implementation
83 //
84 
88 typedef struct mbedtls_aes_context
89 {
90  int nr;
91  uint32_t *rk;
92  uint32_t buf[68];
100 }
102 
103 #if defined(MBEDTLS_CIPHER_MODE_XTS)
104 
108 {
114 #endif /* MBEDTLS_CIPHER_MODE_XTS */
115 
116 #else /* MBEDTLS_AES_ALT */
117 #include "aes_alt.h"
118 #endif /* MBEDTLS_AES_ALT */
119 
129 
138 
139 #if defined(MBEDTLS_CIPHER_MODE_XTS)
140 
149 
158 #endif /* MBEDTLS_CIPHER_MODE_XTS */
159 
175 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
176  unsigned int keybits );
177 
193 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
194  unsigned int keybits );
195 
196 #if defined(MBEDTLS_CIPHER_MODE_XTS)
197 
214  const unsigned char *key,
215  unsigned int keybits );
216 
234  const unsigned char *key,
235  unsigned int keybits );
236 #endif /* MBEDTLS_CIPHER_MODE_XTS */
237 
262  int mode,
263  const unsigned char input[16],
264  unsigned char output[16] );
265 
266 #if defined(MBEDTLS_CIPHER_MODE_CBC)
267 
309  int mode,
310  size_t length,
311  unsigned char iv[16],
312  const unsigned char *input,
313  unsigned char *output );
314 #endif /* MBEDTLS_CIPHER_MODE_CBC */
315 
316 #if defined(MBEDTLS_CIPHER_MODE_XTS)
317 
353  int mode,
354  size_t length,
355  const unsigned char data_unit[16],
356  const unsigned char *input,
357  unsigned char *output );
358 #endif /* MBEDTLS_CIPHER_MODE_XTS */
359 
360 #if defined(MBEDTLS_CIPHER_MODE_CFB)
361 
401  int mode,
402  size_t length,
403  size_t *iv_off,
404  unsigned char iv[16],
405  const unsigned char *input,
406  unsigned char *output );
407 
445  int mode,
446  size_t length,
447  unsigned char iv[16],
448  const unsigned char *input,
449  unsigned char *output );
450 #endif /*MBEDTLS_CIPHER_MODE_CFB */
451 
452 #if defined(MBEDTLS_CIPHER_MODE_OFB)
453 
499  size_t length,
500  size_t *iv_off,
501  unsigned char iv[16],
502  const unsigned char *input,
503  unsigned char *output );
504 
505 #endif /* MBEDTLS_CIPHER_MODE_OFB */
506 
507 #if defined(MBEDTLS_CIPHER_MODE_CTR)
508 
585  size_t length,
586  size_t *nc_off,
587  unsigned char nonce_counter[16],
588  unsigned char stream_block[16],
589  const unsigned char *input,
590  unsigned char *output );
591 #endif /* MBEDTLS_CIPHER_MODE_CTR */
592 
605  const unsigned char input[16],
606  unsigned char output[16] );
607 
620  const unsigned char input[16],
621  unsigned char output[16] );
622 
623 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
624 #if defined(MBEDTLS_DEPRECATED_WARNING)
625 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
626 #else
627 #define MBEDTLS_DEPRECATED
628 #endif
629 
640  const unsigned char input[16],
641  unsigned char output[16] );
642 
654  const unsigned char input[16],
655  unsigned char output[16] );
656 
657 #undef MBEDTLS_DEPRECATED
658 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
659 
660 
661 #if defined(MBEDTLS_SELF_TEST)
662 
668 int mbedtls_aes_self_test( int verbose );
669 
670 #endif /* MBEDTLS_SELF_TEST */
671 
672 #ifdef __cplusplus
673 }
674 #endif
675 
676 #endif /* aes.h */