mbed TLS v2.16.12
aes.h
Go to the documentation of this file.
1 
23 /*
24  * Copyright The Mbed TLS Contributors
25  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
26  *
27  * This file is provided under the Apache License 2.0, or the
28  * GNU General Public License v2.0 or later.
29  *
30  * **********
31  * Apache License 2.0:
32  *
33  * Licensed under the Apache License, Version 2.0 (the "License"); you may
34  * not use this file except in compliance with the License.
35  * You may obtain a copy of the License at
36  *
37  * http://www.apache.org/licenses/LICENSE-2.0
38  *
39  * Unless required by applicable law or agreed to in writing, software
40  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
41  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42  * See the License for the specific language governing permissions and
43  * limitations under the License.
44  *
45  * **********
46  *
47  * **********
48  * GNU General Public License v2.0 or later:
49  *
50  * This program is free software; you can redistribute it and/or modify
51  * it under the terms of the GNU General Public License as published by
52  * the Free Software Foundation; either version 2 of the License, or
53  * (at your option) any later version.
54  *
55  * This program is distributed in the hope that it will be useful,
56  * but WITHOUT ANY WARRANTY; without even the implied warranty of
57  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58  * GNU General Public License for more details.
59  *
60  * You should have received a copy of the GNU General Public License along
61  * with this program; if not, write to the Free Software Foundation, Inc.,
62  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
63  *
64  * **********
65  */
66 
67 #ifndef MBEDTLS_AES_H
68 #define MBEDTLS_AES_H
69 
70 #if !defined(MBEDTLS_CONFIG_FILE)
71 #include "config.h"
72 #else
73 #include MBEDTLS_CONFIG_FILE
74 #endif
75 
76 #include <stddef.h>
77 #include <stdint.h>
78 
79 /* padlock.c and aesni.c rely on these values! */
80 #define MBEDTLS_AES_ENCRYPT 1
81 #define MBEDTLS_AES_DECRYPT 0
83 /* Error codes in range 0x0020-0x0022 */
84 
85 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
86 
87 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
88 
89 /* Error codes in range 0x0021-0x0025 */
91 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
92 
93 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
95 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
96 
97 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
99 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
100 
101 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
102  !defined(inline) && !defined(__cplusplus)
103 #define inline __inline
104 #endif
105 
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
109 
110 #if !defined(MBEDTLS_AES_ALT)
111 // Regular implementation
112 //
113 
117 typedef struct mbedtls_aes_context
118 {
119  int nr;
120  uint32_t *rk;
121  uint32_t buf[68];
129 }
131 
132 #if defined(MBEDTLS_CIPHER_MODE_XTS)
133 
137 {
143 #endif /* MBEDTLS_CIPHER_MODE_XTS */
144 
145 #else /* MBEDTLS_AES_ALT */
146 #include "aes_alt.h"
147 #endif /* MBEDTLS_AES_ALT */
148 
158 
167 
168 #if defined(MBEDTLS_CIPHER_MODE_XTS)
169 
178 
187 #endif /* MBEDTLS_CIPHER_MODE_XTS */
188 
204 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
205  unsigned int keybits );
206 
222 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
223  unsigned int keybits );
224 
225 #if defined(MBEDTLS_CIPHER_MODE_XTS)
226 
243  const unsigned char *key,
244  unsigned int keybits );
245 
263  const unsigned char *key,
264  unsigned int keybits );
265 #endif /* MBEDTLS_CIPHER_MODE_XTS */
266 
291  int mode,
292  const unsigned char input[16],
293  unsigned char output[16] );
294 
295 #if defined(MBEDTLS_CIPHER_MODE_CBC)
296 
338  int mode,
339  size_t length,
340  unsigned char iv[16],
341  const unsigned char *input,
342  unsigned char *output );
343 #endif /* MBEDTLS_CIPHER_MODE_CBC */
344 
345 #if defined(MBEDTLS_CIPHER_MODE_XTS)
346 
382  int mode,
383  size_t length,
384  const unsigned char data_unit[16],
385  const unsigned char *input,
386  unsigned char *output );
387 #endif /* MBEDTLS_CIPHER_MODE_XTS */
388 
389 #if defined(MBEDTLS_CIPHER_MODE_CFB)
390 
430  int mode,
431  size_t length,
432  size_t *iv_off,
433  unsigned char iv[16],
434  const unsigned char *input,
435  unsigned char *output );
436 
474  int mode,
475  size_t length,
476  unsigned char iv[16],
477  const unsigned char *input,
478  unsigned char *output );
479 #endif /*MBEDTLS_CIPHER_MODE_CFB */
480 
481 #if defined(MBEDTLS_CIPHER_MODE_OFB)
482 
528  size_t length,
529  size_t *iv_off,
530  unsigned char iv[16],
531  const unsigned char *input,
532  unsigned char *output );
533 
534 #endif /* MBEDTLS_CIPHER_MODE_OFB */
535 
536 #if defined(MBEDTLS_CIPHER_MODE_CTR)
537 
610  size_t length,
611  size_t *nc_off,
612  unsigned char nonce_counter[16],
613  unsigned char stream_block[16],
614  const unsigned char *input,
615  unsigned char *output );
616 #endif /* MBEDTLS_CIPHER_MODE_CTR */
617 
630  const unsigned char input[16],
631  unsigned char output[16] );
632 
645  const unsigned char input[16],
646  unsigned char output[16] );
647 
648 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
649 #if defined(MBEDTLS_DEPRECATED_WARNING)
650 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
651 #else
652 #define MBEDTLS_DEPRECATED
653 #endif
654 
665  const unsigned char input[16],
666  unsigned char output[16] );
667 
679  const unsigned char input[16],
680  unsigned char output[16] );
681 
682 #undef MBEDTLS_DEPRECATED
683 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
684 
685 
686 #if defined(MBEDTLS_SELF_TEST)
687 
693 int mbedtls_aes_self_test( int verbose );
694 
695 #endif /* MBEDTLS_SELF_TEST */
696 
697 #ifdef __cplusplus
698 }
699 #endif
700 
701 #endif /* aes.h */
uint32_t buf[68]
Definition: aes.h:121
mbedtls_aes_context crypt
Definition: aes.h:138
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.
int mbedtls_aes_self_test(int verbose)
Checkup routine.
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...
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. ...
#define MBEDTLS_DEPRECATED
Definition: aes.h:652
Configuration options (set of defines)
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
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...
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...
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
This function initializes the specified AES XTS context.
The AES XTS context-type definition.
Definition: aes.h:136
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.
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.
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.
int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the decryption key.
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
mbedtls_aes_context tweak
Definition: aes.h:140
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.
uint32_t * rk
Definition: aes.h:120
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. ...
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.
int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the encryption key.
void mbedtls_aes_free(mbedtls_aes_context *ctx)
This function releases and clears the specified AES context.
The AES context-type definition.
Definition: aes.h:117
struct mbedtls_aes_xts_context mbedtls_aes_xts_context
The AES XTS context-type definition.
struct mbedtls_aes_context mbedtls_aes_context
The AES context-type definition.
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_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.