mbed TLS v2.23.0

aes.h
Go to the documentation of this file.
1
23 /*
24 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
25 * SPDX-License-Identifier: Apache-2.0
26 *
27 * Licensed under the Apache License, Version 2.0 (the "License"); you may
28 * not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 * http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
35 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
38 *
39 * This file is part of Mbed TLS (https://tls.mbed.org)
40 */
41
42 #ifndef MBEDTLS_AES_H
43 #define MBEDTLS_AES_H
44
45 #if !defined(MBEDTLS_CONFIG_FILE)
46 #include "mbedtls/config.h"
47 #else
48 #include MBEDTLS_CONFIG_FILE
49 #endif
50
51 #include <stddef.h>
52 #include <stdint.h>
53
54 /* padlock.c and aesni.c rely on these values! */
55 #define MBEDTLS_AES_ENCRYPT 1
56 #define MBEDTLS_AES_DECRYPT 0
58 /* Error codes in range 0x0020-0x0022 */
59 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
60 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
62 /* Error codes in range 0x0021-0x0025 */
63 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
65 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
66 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
68 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
69 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
71 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
72 !defined(inline) && !defined(__cplusplus)
73 #define inline __inline
74 #endif
75
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79
80 #if !defined(MBEDTLS_AES_ALT)
81 // Regular implementation
82 //
83
87 typedef struct mbedtls_aes_context
88 {
89 int nr;
90 uint32_t *rk;
91 uint32_t buf[68];
99 }
100 mbedtls_aes_context;
101
102 #if defined(MBEDTLS_CIPHER_MODE_XTS)
103
106 typedef struct mbedtls_aes_xts_context
107 {
108 mbedtls_aes_context crypt;
110 mbedtls_aes_context tweak;
112 } mbedtls_aes_xts_context;
113 #endif /* MBEDTLS_CIPHER_MODE_XTS */
114
115 #else /* MBEDTLS_AES_ALT */
116 #include "aes_alt.h"
117 #endif /* MBEDTLS_AES_ALT */
118
127 void mbedtls_aes_init( mbedtls_aes_context *ctx );
128
136 void mbedtls_aes_free( mbedtls_aes_context *ctx );
137
138 #if defined(MBEDTLS_CIPHER_MODE_XTS)
139
147 void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
148
156 void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
157 #endif /* MBEDTLS_CIPHER_MODE_XTS */
158
174 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
175 unsigned int keybits );
176
192 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
193 unsigned int keybits );
194
195 #if defined(MBEDTLS_CIPHER_MODE_XTS)
196
212 int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
213 const unsigned char *key,
214 unsigned int keybits );
215
232 int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
233 const unsigned char *key,
234 unsigned int keybits );
235 #endif /* MBEDTLS_CIPHER_MODE_XTS */
236
260 int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
261 int mode,
262 const unsigned char input[16],
263 unsigned char output[16] );
264
265 #if defined(MBEDTLS_CIPHER_MODE_CBC)
266
307 int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
308 int mode,
309 size_t length,
310 unsigned char iv[16],
311 const unsigned char *input,
312 unsigned char *output );
313 #endif /* MBEDTLS_CIPHER_MODE_CBC */
314
315 #if defined(MBEDTLS_CIPHER_MODE_XTS)
316
351 int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
352 int mode,
353 size_t length,
354 const unsigned char data_unit[16],
355 const unsigned char *input,
356 unsigned char *output );
357 #endif /* MBEDTLS_CIPHER_MODE_XTS */
358
359 #if defined(MBEDTLS_CIPHER_MODE_CFB)
360
399 int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
400 int mode,
401 size_t length,
402 size_t *iv_off,
403 unsigned char iv[16],
404 const unsigned char *input,
405 unsigned char *output );
406
443 int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
444 int mode,
445 size_t length,
446 unsigned char iv[16],
447 const unsigned char *input,
448 unsigned char *output );
449 #endif /*MBEDTLS_CIPHER_MODE_CFB */
450
451 #if defined(MBEDTLS_CIPHER_MODE_OFB)
452
497 int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
498 size_t length,
499 size_t *iv_off,
500 unsigned char iv[16],
501 const unsigned char *input,
502 unsigned char *output );
503
504 #endif /* MBEDTLS_CIPHER_MODE_OFB */
505
506 #if defined(MBEDTLS_CIPHER_MODE_CTR)
507
583 int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
584 size_t length,
585 size_t *nc_off,
586 unsigned char nonce_counter[16],
587 unsigned char stream_block[16],
588 const unsigned char *input,
589 unsigned char *output );
590 #endif /* MBEDTLS_CIPHER_MODE_CTR */
591
603 int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
604 const unsigned char input[16],
605 unsigned char output[16] );
606
618 int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
619 const unsigned char input[16],
620 unsigned char output[16] );
621
622 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
623 #if defined(MBEDTLS_DEPRECATED_WARNING)
624 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
625 #else
626 #define MBEDTLS_DEPRECATED
627 #endif
628
638 MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
639 const unsigned char input[16],
640 unsigned char output[16] );
641
652 MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
653 const unsigned char input[16],
654 unsigned char output[16] );
655
656 #undef MBEDTLS_DEPRECATED
657 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
658
659
660 #if defined(MBEDTLS_SELF_TEST)
661
667 int mbedtls_aes_self_test( int verbose );
668
669 #endif /* MBEDTLS_SELF_TEST */
670
671 #ifdef __cplusplus
672 }
673 #endif
674
675 #endif /* aes.h */
mbedtls_aes_xts_context::tweak
mbedtls_aes_context tweak
Definition: aes.h:110
mbedtls_aes_self_test
int mbedtls_aes_self_test(int verbose)
Checkup routine.
mbedtls_aes_encrypt
MBEDTLS_DEPRECATED void mbedtls_aes_encrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16])
Deprecated internal AES block encryption function without return value.
mbedtls_aes_context::buf
uint32_t buf[68]
Definition: aes.h:91
mbedtls_aes_crypt_ecb
int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
This function performs an AES single-block encryption or decryption operation.
mbedtls_aes_crypt_xts
int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char *input, unsigned char *output)
This function performs an AES-XTS encryption or decryption operation for an entire XTS data unit.
mbedtls_aes_decrypt
MBEDTLS_DEPRECATED void mbedtls_aes_decrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16])
Deprecated internal AES block decryption function without return value.
mbedtls_internal_aes_decrypt
int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16])
Internal AES block decryption function. This is only exposed to allow overriding it using see MBEDTLS...
mbedtls_aes_xts_setkey_enc
int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits)
This function prepares an XTS context for encryption and sets the encryption key.
mbedtls_aes_xts_context
The AES XTS context-type definition.
Definition: aes.h:107
mbedtls_internal_aes_encrypt
int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16])
Internal AES block encryption function. This is only exposed to allow overriding it using MBEDTLS_AES...
mbedtls_aes_crypt_cfb8
int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CFB8 encryption or decryption operation.
mbedtls_aes_setkey_dec
int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the decryption key.
mbedtls_aes_crypt_ctr
int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CTR encryption or decryption operation.
mbedtls_aes_xts_setkey_dec
int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits)
This function prepares an XTS context for decryption and sets the decryption key.
mbedtls_aes_xts_context
struct mbedtls_aes_xts_context mbedtls_aes_xts_context
The AES XTS context-type definition.
mbedtls_aes_context
The AES context-type definition.
Definition: aes.h:88
mbedtls_aes_crypt_cbc
int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CBC encryption or decryption operation on full blocks.
mbedtls_aes_xts_context::crypt
mbedtls_aes_context crypt
Definition: aes.h:108
mbedtls_aes_context::nr
int nr
Definition: aes.h:89
mbedtls_aes_free
void mbedtls_aes_free(mbedtls_aes_context *ctx)
This function releases and clears the specified AES context.
mbedtls_aes_context::rk
uint32_t * rk
Definition: aes.h:90
config.h
Configuration options (set of defines)
mbedtls_aes_init
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
mbedtls_aes_crypt_cfb128
int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CFB128 encryption or decryption operation.
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: aes.h:626
mbedtls_aes_xts_init
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
This function initializes the specified AES XTS context.
mbedtls_aes_context
struct mbedtls_aes_context mbedtls_aes_context
The AES context-type definition.
mbedtls_aes_crypt_ofb
int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-OFB (Output Feedback Mode) encryption or decryption operation.
mbedtls_aes_setkey_enc
int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the encryption key.
mbedtls_aes_xts_free
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.