mbed TLS v2.7.6
aes.h
Go to the documentation of this file.
1 
15 /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
16  * SPDX-License-Identifier: Apache-2.0
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License"); you may
19  * not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  *
30  * This file is part of Mbed TLS (https://tls.mbed.org)
31  */
32 
33 #ifndef MBEDTLS_AES_H
34 #define MBEDTLS_AES_H
35 
36 #if !defined(MBEDTLS_CONFIG_FILE)
37 #include "config.h"
38 #else
39 #include MBEDTLS_CONFIG_FILE
40 #endif
41 
42 #include <stddef.h>
43 #include <stdint.h>
44 
45 /* padlock.c and aesni.c rely on these values! */
46 #define MBEDTLS_AES_ENCRYPT 1
47 #define MBEDTLS_AES_DECRYPT 0
49 /* Error codes in range 0x0020-0x0022 */
50 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
51 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
53 /* Error codes in range 0x0023-0x0025 */
54 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
55 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
57 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
58  !defined(inline) && !defined(__cplusplus)
59 #define inline __inline
60 #endif
61 
62 #if !defined(MBEDTLS_AES_ALT)
63 // Regular implementation
64 //
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
73 typedef struct
74 {
75  int nr;
76  uint32_t *rk;
77  uint32_t buf[68];
85 }
87 
97 
104 
118 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
119  unsigned int keybits );
120 
133 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
134  unsigned int keybits );
135 
157  int mode,
158  const unsigned char input[16],
159  unsigned char output[16] );
160 
161 #if defined(MBEDTLS_CIPHER_MODE_CBC)
162 
199  int mode,
200  size_t length,
201  unsigned char iv[16],
202  const unsigned char *input,
203  unsigned char *output );
204 #endif /* MBEDTLS_CIPHER_MODE_CBC */
205 
206 #if defined(MBEDTLS_CIPHER_MODE_CFB)
207 
242  int mode,
243  size_t length,
244  size_t *iv_off,
245  unsigned char iv[16],
246  const unsigned char *input,
247  unsigned char *output );
248 
282  int mode,
283  size_t length,
284  unsigned char iv[16],
285  const unsigned char *input,
286  unsigned char *output );
287 #endif /*MBEDTLS_CIPHER_MODE_CFB */
288 
289 #if defined(MBEDTLS_CIPHER_MODE_CTR)
290 
319  size_t length,
320  size_t *nc_off,
321  unsigned char nonce_counter[16],
322  unsigned char stream_block[16],
323  const unsigned char *input,
324  unsigned char *output );
325 #endif /* MBEDTLS_CIPHER_MODE_CTR */
326 
339  const unsigned char input[16],
340  unsigned char output[16] );
341 
354  const unsigned char input[16],
355  unsigned char output[16] );
356 
357 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
358 #if defined(MBEDTLS_DEPRECATED_WARNING)
359 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
360 #else
361 #define MBEDTLS_DEPRECATED
362 #endif
363 
374  const unsigned char input[16],
375  unsigned char output[16] );
376 
388  const unsigned char input[16],
389  unsigned char output[16] );
390 
391 #undef MBEDTLS_DEPRECATED
392 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
393 
394 #ifdef __cplusplus
395 }
396 #endif
397 
398 #else /* MBEDTLS_AES_ALT */
399 #include "aes_alt.h"
400 #endif /* MBEDTLS_AES_ALT */
401 
402 #ifdef __cplusplus
403 extern "C" {
404 #endif
405 
411 int mbedtls_aes_self_test( int verbose );
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 
417 #endif /* aes.h */
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.
#define MBEDTLS_DEPRECATED
Definition: aes.h:361
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_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.
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:76
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:73
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.