PolarSSL v1.1.4
aes.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_AES_H
28 #define POLARSSL_AES_H
29 
30 #include <string.h>
31 
32 #define AES_ENCRYPT 1
33 #define AES_DECRYPT 0
34 
35 #define POLARSSL_ERR_AES_INVALID_KEY_LENGTH -0x0020
36 #define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH -0x0022
41 typedef struct
42 {
43  int nr;
44  unsigned long *rk;
45  unsigned long buf[68];
46 }
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
62 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize );
63 
73 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize );
74 
85 int aes_crypt_ecb( aes_context *ctx,
86  int mode,
87  const unsigned char input[16],
88  unsigned char output[16] );
89 
104 int aes_crypt_cbc( aes_context *ctx,
105  int mode,
106  size_t length,
107  unsigned char iv[16],
108  const unsigned char *input,
109  unsigned char *output );
110 
129 int aes_crypt_cfb128( aes_context *ctx,
130  int mode,
131  size_t length,
132  size_t *iv_off,
133  unsigned char iv[16],
134  const unsigned char *input,
135  unsigned char *output );
136 
137 /*
138  * \brief AES-CTR buffer encryption/decryption
139  *
140  * Warning: You have to keep the maximum use of your counter in mind!
141  *
142  * Note: Due to the nature of CTR you should use the same key schedule for
143  * both encryption and decryption. So a context initialized with
144  * aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
145  *
146  * \param length The length of the data
147  * \param nc_off The offset in the current stream_block (for resuming
148  * within current cipher stream). The offset pointer to
149  * should be 0 at the start of a stream.
150  * \param nonce_counter The 128-bit nonce and counter.
151  * \param stream_block The saved stream-block for resuming. Is overwritten
152  * by the function.
153  * \param input The input data stream
154  * \param output The output data stream
155  *
156  * \return 0 if successful
157  */
158 int aes_crypt_ctr( aes_context *ctx,
159  size_t length,
160  size_t *nc_off,
161  unsigned char nonce_counter[16],
162  unsigned char stream_block[16],
163  const unsigned char *input,
164  unsigned char *output );
170 int aes_self_test( int verbose );
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* aes.h */