mbed TLS v2.14.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: Apache-2.0
25  *
26  * Licensed under the Apache License, Version 2.0 (the "License"); you may
27  * not use this file except in compliance with the License.
28  * You may obtain a copy of the License at
29  *
30  * http://www.apache.org/licenses/LICENSE-2.0
31  *
32  * Unless required by applicable law or agreed to in writing, software
33  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
34  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35  * See the License for the specific language governing permissions and
36  * limitations under the License.
37  *
38  * This file is part of Mbed TLS (https://tls.mbed.org)
39  */
40 
41 #ifndef MBEDTLS_AES_H
42 #define MBEDTLS_AES_H
43 
44 #if !defined(MBEDTLS_CONFIG_FILE)
45 #include "config.h"
46 #else
47 #include MBEDTLS_CONFIG_FILE
48 #endif
49 
50 #include <stddef.h>
51 #include <stdint.h>
52 
53 /* padlock.c and aesni.c rely on these values! */
54 #define MBEDTLS_AES_ENCRYPT 1
55 #define MBEDTLS_AES_DECRYPT 0
57 /* Error codes in range 0x0020-0x0022 */
58 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
59 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
61 /* Error codes in range 0x0021-0x0025 */
62 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
64 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
65 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
67 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
68 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
70 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
71  !defined(inline) && !defined(__cplusplus)
72 #define inline __inline
73 #endif
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 #if !defined(MBEDTLS_AES_ALT)
80 // Regular implementation
81 //
82 
86 typedef struct mbedtls_aes_context
87 {
88  int nr;
89  uint32_t *rk;
90  uint32_t buf[68];
98 }
100 
101 #if defined(MBEDTLS_CIPHER_MODE_XTS)
102 
106 {
112 #endif /* MBEDTLS_CIPHER_MODE_XTS */
113 
114 #else /* MBEDTLS_AES_ALT */
115 #include "aes_alt.h"
116 #endif /* MBEDTLS_AES_ALT */
117 
127 
134 
135 #if defined(MBEDTLS_CIPHER_MODE_XTS)
136 
145 
152 #endif /* MBEDTLS_CIPHER_MODE_XTS */
153 
167 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
168  unsigned int keybits );
169 
183 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
184  unsigned int keybits );
185 
186 #if defined(MBEDTLS_CIPHER_MODE_XTS)
187 
202  const unsigned char *key,
203  unsigned int keybits );
204 
220  const unsigned char *key,
221  unsigned int keybits );
222 #endif /* MBEDTLS_CIPHER_MODE_XTS */
223 
245  int mode,
246  const unsigned char input[16],
247  unsigned char output[16] );
248 
249 #if defined(MBEDTLS_CIPHER_MODE_CBC)
250 
288  int mode,
289  size_t length,
290  unsigned char iv[16],
291  const unsigned char *input,
292  unsigned char *output );
293 #endif /* MBEDTLS_CIPHER_MODE_CBC */
294 
295 #if defined(MBEDTLS_CIPHER_MODE_XTS)
296 
331  int mode,
332  size_t length,
333  const unsigned char data_unit[16],
334  const unsigned char *input,
335  unsigned char *output );
336 #endif /* MBEDTLS_CIPHER_MODE_XTS */
337 
338 #if defined(MBEDTLS_CIPHER_MODE_CFB)
339 
374  int mode,
375  size_t length,
376  size_t *iv_off,
377  unsigned char iv[16],
378  const unsigned char *input,
379  unsigned char *output );
380 
414  int mode,
415  size_t length,
416  unsigned char iv[16],
417  const unsigned char *input,
418  unsigned char *output );
419 #endif /*MBEDTLS_CIPHER_MODE_CFB */
420 
421 #if defined(MBEDTLS_CIPHER_MODE_OFB)
422 
463  size_t length,
464  size_t *iv_off,
465  unsigned char iv[16],
466  const unsigned char *input,
467  unsigned char *output );
468 
469 #endif /* MBEDTLS_CIPHER_MODE_OFB */
470 
471 #if defined(MBEDTLS_CIPHER_MODE_CTR)
472 
543  size_t length,
544  size_t *nc_off,
545  unsigned char nonce_counter[16],
546  unsigned char stream_block[16],
547  const unsigned char *input,
548  unsigned char *output );
549 #endif /* MBEDTLS_CIPHER_MODE_CTR */
550 
563  const unsigned char input[16],
564  unsigned char output[16] );
565 
578  const unsigned char input[16],
579  unsigned char output[16] );
580 
581 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
582 #if defined(MBEDTLS_DEPRECATED_WARNING)
583 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
584 #else
585 #define MBEDTLS_DEPRECATED
586 #endif
587 
598  const unsigned char input[16],
599  unsigned char output[16] );
600 
612  const unsigned char input[16],
613  unsigned char output[16] );
614 
615 #undef MBEDTLS_DEPRECATED
616 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
617 
624 int mbedtls_aes_self_test( int verbose );
625 
626 #ifdef __cplusplus
627 }
628 #endif
629 
630 #endif /* aes.h */