mbed TLS v2.16.0: aes.h Source File

mbed TLS v2.16.0

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 }
99 mbedtls_aes_context;
100
101 #if defined(MBEDTLS_CIPHER_MODE_XTS)
102
105 typedef struct mbedtls_aes_xts_context
106 {
107 mbedtls_aes_context crypt;
109 mbedtls_aes_context tweak;
111 } mbedtls_aes_xts_context;
112 #endif /* MBEDTLS_CIPHER_MODE_XTS */
113
114 #else /* MBEDTLS_AES_ALT */
115 #include "aes_alt.h"
116 #endif /* MBEDTLS_AES_ALT */
117
126 void mbedtls_aes_init( mbedtls_aes_context *ctx );
127
135 void mbedtls_aes_free( mbedtls_aes_context *ctx );
136
137 #if defined(MBEDTLS_CIPHER_MODE_XTS)
138
146 void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
147
155 void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
156 #endif /* MBEDTLS_CIPHER_MODE_XTS */
157
173 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
174 unsigned int keybits );
175
191 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
192 unsigned int keybits );
193
194 #if defined(MBEDTLS_CIPHER_MODE_XTS)
195
211 int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
212 const unsigned char *key,
213 unsigned int keybits );
214
231 int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
232 const unsigned char *key,
233 unsigned int keybits );
234 #endif /* MBEDTLS_CIPHER_MODE_XTS */
235
259 int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
260 int mode,
261 const unsigned char input[16],
262 unsigned char output[16] );
263
264 #if defined(MBEDTLS_CIPHER_MODE_CBC)
265
306 int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
307 int mode,
308 size_t length,
309 unsigned char iv[16],
310 const unsigned char *input,
311 unsigned char *output );
312 #endif /* MBEDTLS_CIPHER_MODE_CBC */
313
314 #if defined(MBEDTLS_CIPHER_MODE_XTS)
315
350 int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
351 int mode,
352 size_t length,
353 const unsigned char data_unit[16],
354 const unsigned char *input,
355 unsigned char *output );
356 #endif /* MBEDTLS_CIPHER_MODE_XTS */
357
358 #if defined(MBEDTLS_CIPHER_MODE_CFB)
359
398 int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
399 int mode,
400 size_t length,
401 size_t *iv_off,
402 unsigned char iv[16],
403 const unsigned char *input,
404 unsigned char *output );
405
442 int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
443 int mode,
444 size_t length,
445 unsigned char iv[16],
446 const unsigned char *input,
447 unsigned char *output );
448 #endif /*MBEDTLS_CIPHER_MODE_CFB */
449
450 #if defined(MBEDTLS_CIPHER_MODE_OFB)
451
496 int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
497 size_t length,
498 size_t *iv_off,
499 unsigned char iv[16],
500 const unsigned char *input,
501 unsigned char *output );
502
503 #endif /* MBEDTLS_CIPHER_MODE_OFB */
504
505 #if defined(MBEDTLS_CIPHER_MODE_CTR)
506
582 int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
583 size_t length,
584 size_t *nc_off,
585 unsigned char nonce_counter[16],
586 unsigned char stream_block[16],
587 const unsigned char *input,
588 unsigned char *output );
589 #endif /* MBEDTLS_CIPHER_MODE_CTR */
590
602 int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
603 const unsigned char input[16],
604 unsigned char output[16] );
605
617 int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
618 const unsigned char input[16],
619 unsigned char output[16] );
620
621 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
622 #if defined(MBEDTLS_DEPRECATED_WARNING)
623 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
624 #else
625 #define MBEDTLS_DEPRECATED
626 #endif
627
637 MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
638 const unsigned char input[16],
639 unsigned char output[16] );
640
651 MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
652 const unsigned char input[16],
653 unsigned char output[16] );
654
655 #undef MBEDTLS_DEPRECATED
656 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
657
664 int mbedtls_aes_self_test( int verbose );
665
666 #ifdef __cplusplus
667 }
668 #endif
669
670 #endif /* aes.h */
mbedtls_aes_context::buf
uint32_t buf[68]
Definition: aes.h:90
mbedtls_aes_xts_context::crypt
mbedtls_aes_context crypt
Definition: aes.h:107
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_self_test
int mbedtls_aes_self_test(int verbose)
Checkup routine.
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_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_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: aes.h:625
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_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_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_context::nr
int nr
Definition: aes.h:88
mbedtls_aes_xts_init
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
This function initializes the specified AES XTS context.
mbedtls_aes_xts_context
The AES XTS context-type definition.
Definition: aes.h:105
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_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_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_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_xts_free
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
mbedtls_aes_xts_context::tweak
mbedtls_aes_context tweak
Definition: aes.h:109
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_aes_context::rk
uint32_t * rk
Definition: aes.h:89
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_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_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_free
void mbedtls_aes_free(mbedtls_aes_context *ctx)
This function releases and clears the specified AES context.
mbedtls_aes_context
The AES context-type definition.
Definition: aes.h:86
mbedtls_aes_xts_context
struct mbedtls_aes_xts_context mbedtls_aes_xts_context
The AES XTS context-type definition.
mbedtls_aes_context
struct mbedtls_aes_context mbedtls_aes_context
The AES context-type definition.
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_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.