blob: 4e87d36153e3a6b689b89bc8b554f89cb1de9946 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file aes.h
3 */
Paul Bakker40e46942009-01-03 21:51:57 +00004#ifndef POLARSSL_AES_H
5#define POLARSSL_AES_H
Paul Bakker5121ce52009-01-03 21:22:43 +00006
7#define AES_ENCRYPT 1
8#define AES_DECRYPT 0
9
10/**
11 * \brief AES context structure
12 */
13typedef struct
14{
15 int nr; /*!< number of rounds */
16 unsigned long *rk; /*!< AES round keys */
17 unsigned long buf[68]; /*!< unaligned data */
18}
19aes_context;
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/**
26 * \brief AES key schedule (encryption)
27 *
28 * \param ctx AES context to be initialized
29 * \param key encryption key
30 * \param keysize must be 128, 192 or 256
31 */
32void aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize );
33
34/**
35 * \brief AES key schedule (decryption)
36 *
37 * \param ctx AES context to be initialized
38 * \param key decryption key
39 * \param keysize must be 128, 192 or 256
40 */
41void aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize );
42
43/**
44 * \brief AES-ECB block encryption/decryption
45 *
46 * \param ctx AES context
47 * \param mode AES_ENCRYPT or AES_DECRYPT
48 * \param input 16-byte input block
49 * \param output 16-byte output block
50 */
51void aes_crypt_ecb( aes_context *ctx,
52 int mode,
53 unsigned char input[16],
54 unsigned char output[16] );
55
56/**
57 * \brief AES-CBC buffer encryption/decryption
58 *
59 * \param ctx AES context
60 * \param mode AES_ENCRYPT or AES_DECRYPT
61 * \param length length of the input data
62 * \param iv initialization vector (updated after use)
63 * \param input buffer holding the input data
64 * \param output buffer holding the output data
65 */
66void aes_crypt_cbc( aes_context *ctx,
67 int mode,
68 int length,
69 unsigned char iv[16],
70 unsigned char *input,
71 unsigned char *output );
72
73/**
74 * \brief AES-CFB128 buffer encryption/decryption
75 *
76 * \param ctx AES context
77 * \param mode AES_ENCRYPT or AES_DECRYPT
78 * \param length length of the input data
79 * \param iv_off offset in IV (updated after use)
80 * \param iv initialization vector (updated after use)
81 * \param input buffer holding the input data
82 * \param output buffer holding the output data
83 */
84void aes_crypt_cfb128( aes_context *ctx,
85 int mode,
86 int length,
87 int *iv_off,
88 unsigned char iv[16],
89 unsigned char *input,
90 unsigned char *output );
91
92/**
93 * \brief Checkup routine
94 *
95 * \return 0 if successful, or 1 if the test failed
96 */
97int aes_self_test( int verbose );
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif /* aes.h */