PolarSSL v1.3.9
aes.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_AES_H
28 #define POLARSSL_AES_H
29 
30 #if !defined(POLARSSL_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include POLARSSL_CONFIG_FILE
34 #endif
35 
36 #include <string.h>
37 
38 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
39 #include <basetsd.h>
40 typedef UINT32 uint32_t;
41 #else
42 #include <inttypes.h>
43 #endif
44 
45 /* padlock.c and aesni.c rely on these values! */
46 #define AES_ENCRYPT 1
47 #define AES_DECRYPT 0
48 
49 #define POLARSSL_ERR_AES_INVALID_KEY_LENGTH -0x0020
50 #define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH -0x0022
52 #if !defined(POLARSSL_AES_ALT)
53 // Regular implementation
54 //
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
68 typedef struct
69 {
70  int nr;
71  uint32_t *rk;
72  uint32_t buf[68];
73 }
75 
81 void aes_init( aes_context *ctx );
82 
88 void aes_free( aes_context *ctx );
89 
99 int aes_setkey_enc( aes_context *ctx, const unsigned char *key,
100  unsigned int keysize );
101 
111 int aes_setkey_dec( aes_context *ctx, const unsigned char *key,
112  unsigned int keysize );
113 
124 int aes_crypt_ecb( aes_context *ctx,
125  int mode,
126  const unsigned char input[16],
127  unsigned char output[16] );
128 
129 #if defined(POLARSSL_CIPHER_MODE_CBC)
130 
144 int aes_crypt_cbc( aes_context *ctx,
145  int mode,
146  size_t length,
147  unsigned char iv[16],
148  const unsigned char *input,
149  unsigned char *output );
150 #endif /* POLARSSL_CIPHER_MODE_CBC */
151 
152 #if defined(POLARSSL_CIPHER_MODE_CFB)
153 
170 int aes_crypt_cfb128( aes_context *ctx,
171  int mode,
172  size_t length,
173  size_t *iv_off,
174  unsigned char iv[16],
175  const unsigned char *input,
176  unsigned char *output );
177 
194 int aes_crypt_cfb8( aes_context *ctx,
195  int mode,
196  size_t length,
197  unsigned char iv[16],
198  const unsigned char *input,
199  unsigned char *output );
200 #endif /*POLARSSL_CIPHER_MODE_CFB */
201 
202 #if defined(POLARSSL_CIPHER_MODE_CTR)
203 
225 int aes_crypt_ctr( aes_context *ctx,
226  size_t length,
227  size_t *nc_off,
228  unsigned char nonce_counter[16],
229  unsigned char stream_block[16],
230  const unsigned char *input,
231  unsigned char *output );
232 #endif /* POLARSSL_CIPHER_MODE_CTR */
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #else /* POLARSSL_AES_ALT */
239 #include "aes_alt.h"
240 #endif /* POLARSSL_AES_ALT */
241 
242 #ifdef __cplusplus
243 extern "C" {
244 #endif
245 
251 int aes_self_test( int verbose );
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 #endif /* aes.h */
int aes_crypt_cfb128(aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CFB128 buffer encryption/decryption.
AES context structure.
Definition: aes.h:68
Configuration options (set of defines)
int aes_setkey_dec(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (decryption)
int aes_crypt_cbc(aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes) ...
int aes_self_test(int verbose)
Checkup routine.
int aes_crypt_cfb8(aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CFB8 buffer encryption/decryption.
void aes_free(aes_context *ctx)
Clear AES context.
uint32_t * rk
Definition: aes.h:71
int nr
Definition: aes.h:70
int aes_setkey_enc(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (encryption)
int aes_crypt_ecb(aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
AES-ECB block encryption/decryption.
void aes_init(aes_context *ctx)
Initialize AES context.
int aes_crypt_ctr(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)
AES-CTR buffer encryption/decryption.