00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef MBEDTLS_AES_H
00034 #define MBEDTLS_AES_H
00035
00036 #if !defined(MBEDTLS_CONFIG_FILE)
00037 #include "config.h"
00038 #else
00039 #include MBEDTLS_CONFIG_FILE
00040 #endif
00041
00042 #include <stddef.h>
00043 #include <stdint.h>
00044
00045
00046 #define MBEDTLS_AES_ENCRYPT 1
00047 #define MBEDTLS_AES_DECRYPT 0
00049
00050 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
00051 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
00053
00054 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
00055 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
00057 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
00058 !defined(inline) && !defined(__cplusplus)
00059 #define inline __inline
00060 #endif
00061
00062 #if !defined(MBEDTLS_AES_ALT)
00063
00064
00065
00066 #ifdef __cplusplus
00067 extern "C" {
00068 #endif
00069
00073 typedef struct
00074 {
00075 int nr;
00076 uint32_t *rk;
00077 uint32_t buf[68];
00085 }
00086 mbedtls_aes_context;
00087
00096 void mbedtls_aes_init( mbedtls_aes_context *ctx );
00097
00103 void mbedtls_aes_free( mbedtls_aes_context *ctx );
00104
00118 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
00119 unsigned int keybits );
00120
00133 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
00134 unsigned int keybits );
00135
00156 int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
00157 int mode,
00158 const unsigned char input[16],
00159 unsigned char output[16] );
00160
00161 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00162
00198 int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
00199 int mode,
00200 size_t length,
00201 unsigned char iv[16],
00202 const unsigned char *input,
00203 unsigned char *output );
00204 #endif
00205
00206 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00207
00241 int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
00242 int mode,
00243 size_t length,
00244 size_t *iv_off,
00245 unsigned char iv[16],
00246 const unsigned char *input,
00247 unsigned char *output );
00248
00281 int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
00282 int mode,
00283 size_t length,
00284 unsigned char iv[16],
00285 const unsigned char *input,
00286 unsigned char *output );
00287 #endif
00288
00289 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00290
00318 int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
00319 size_t length,
00320 size_t *nc_off,
00321 unsigned char nonce_counter[16],
00322 unsigned char stream_block[16],
00323 const unsigned char *input,
00324 unsigned char *output );
00325 #endif
00326
00338 int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
00339 const unsigned char input[16],
00340 unsigned char output[16] );
00341
00353 int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
00354 const unsigned char input[16],
00355 unsigned char output[16] );
00356
00357 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00358 #if defined(MBEDTLS_DEPRECATED_WARNING)
00359 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
00360 #else
00361 #define MBEDTLS_DEPRECATED
00362 #endif
00363
00373 MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
00374 const unsigned char input[16],
00375 unsigned char output[16] );
00376
00387 MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
00388 const unsigned char input[16],
00389 unsigned char output[16] );
00390
00391 #undef MBEDTLS_DEPRECATED
00392 #endif
00393
00394 #ifdef __cplusplus
00395 }
00396 #endif
00397
00398 #else
00399 #include "aes_alt.h"
00400 #endif
00401
00402 #ifdef __cplusplus
00403 extern "C" {
00404 #endif
00405
00411 int mbedtls_aes_self_test( int verbose );
00412
00413 #ifdef __cplusplus
00414 }
00415 #endif
00416
00417 #endif