mbed TLS v2.16.7
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 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  * This file is part of Mbed TLS (https://tls.mbed.org)
67  */
68 
69 #ifndef MBEDTLS_AES_H
70 #define MBEDTLS_AES_H
71 
72 #if !defined(MBEDTLS_CONFIG_FILE)
73 #include "config.h"
74 #else
75 #include MBEDTLS_CONFIG_FILE
76 #endif
77 
78 #include <stddef.h>
79 #include <stdint.h>
80 
81 /* padlock.c and aesni.c rely on these values! */
82 #define MBEDTLS_AES_ENCRYPT 1
83 #define MBEDTLS_AES_DECRYPT 0
85 /* Error codes in range 0x0020-0x0022 */
86 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
87 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
89 /* Error codes in range 0x0021-0x0025 */
90 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
92 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
93 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
95 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
96 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
98 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
99  !defined(inline) && !defined(__cplusplus)
100 #define inline __inline
101 #endif
102 
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
107 #if !defined(MBEDTLS_AES_ALT)
108 // Regular implementation
109 //
110 
114 typedef struct mbedtls_aes_context
115 {
116  int nr;
117  uint32_t *rk;
118  uint32_t buf[68];
126 }
128 
129 #if defined(MBEDTLS_CIPHER_MODE_XTS)
130 
134 {
140 #endif /* MBEDTLS_CIPHER_MODE_XTS */
141 
142 #else /* MBEDTLS_AES_ALT */
143 #include "aes_alt.h"
144 #endif /* MBEDTLS_AES_ALT */
145 
155 
164 
165 #if defined(MBEDTLS_CIPHER_MODE_XTS)
166 
175 
184 #endif /* MBEDTLS_CIPHER_MODE_XTS */
185 
201 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
202  unsigned int keybits );
203 
219 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
220  unsigned int keybits );
221 
222 #if defined(MBEDTLS_CIPHER_MODE_XTS)
223 
240  const unsigned char *key,
241  unsigned int keybits );
242 
260  const unsigned char *key,
261  unsigned int keybits );
262 #endif /* MBEDTLS_CIPHER_MODE_XTS */
263 
288  int mode,
289  const unsigned char input[16],
290  unsigned char output[16] );
291 
292 #if defined(MBEDTLS_CIPHER_MODE_CBC)
293 
335  int mode,
336  size_t length,
337  unsigned char iv[16],
338  const unsigned char *input,
339  unsigned char *output );
340 #endif /* MBEDTLS_CIPHER_MODE_CBC */
341 
342 #if defined(MBEDTLS_CIPHER_MODE_XTS)
343 
379  int mode,
380  size_t length,
381  const unsigned char data_unit[16],
382  const unsigned char *input,
383  unsigned char *output );
384 #endif /* MBEDTLS_CIPHER_MODE_XTS */
385 
386 #if defined(MBEDTLS_CIPHER_MODE_CFB)
387 
427  int mode,
428  size_t length,
429  size_t *iv_off,
430  unsigned char iv[16],
431  const unsigned char *input,
432  unsigned char *output );
433 
471  int mode,
472  size_t length,
473  unsigned char iv[16],
474  const unsigned char *input,
475  unsigned char *output );
476 #endif /*MBEDTLS_CIPHER_MODE_CFB */
477 
478 #if defined(MBEDTLS_CIPHER_MODE_OFB)
479 
525  size_t length,
526  size_t *iv_off,
527  unsigned char iv[16],
528  const unsigned char *input,
529  unsigned char *output );
530 
531 #endif /* MBEDTLS_CIPHER_MODE_OFB */
532 
533 #if defined(MBEDTLS_CIPHER_MODE_CTR)
534 
611  size_t length,
612  size_t *nc_off,
613  unsigned char nonce_counter[16],
614  unsigned char stream_block[16],
615  const unsigned char *input,
616  unsigned char *output );
617 #endif /* MBEDTLS_CIPHER_MODE_CTR */
618 
631  const unsigned char input[16],
632  unsigned char output[16] );
633 
646  const unsigned char input[16],
647  unsigned char output[16] );
648 
649 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
650 #if defined(MBEDTLS_DEPRECATED_WARNING)
651 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
652 #else
653 #define MBEDTLS_DEPRECATED
654 #endif
655 
666  const unsigned char input[16],
667  unsigned char output[16] );
668 
680  const unsigned char input[16],
681  unsigned char output[16] );
682 
683 #undef MBEDTLS_DEPRECATED
684 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
685 
686 
687 #if defined(MBEDTLS_SELF_TEST)
688 
694 int mbedtls_aes_self_test( int verbose );
695 
696 #endif /* MBEDTLS_SELF_TEST */
697 
698 #ifdef __cplusplus
699 }
700 #endif
701 
702 #endif /* aes.h */
uint32_t buf[68]
Definition: aes.h:118
mbedtls_aes_context crypt
Definition: aes.h:135
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:653
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:133
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:137
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:117
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:114
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.