4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
6 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef TROPICSSL_AES_H
36 #define TROPICSSL_AES_H
42 * \brief AES context structure
45 int nr
; /*!< number of rounds */
46 unsigned long *rk
; /*!< AES round keys */
47 unsigned long buf
[68]; /*!< unaligned data */
55 * \brief AES key schedule (encryption)
57 * \param ctx AES context to be initialized
58 * \param key encryption key
59 * \param keysize must be 128, 192 or 256
61 void aes_setkey_enc(aes_context
* ctx
, const unsigned char *key
, int keysize
);
64 * \brief AES key schedule (decryption)
66 * \param ctx AES context to be initialized
67 * \param key decryption key
68 * \param keysize must be 128, 192 or 256
70 void aes_setkey_dec(aes_context
* ctx
, const unsigned char *key
, int keysize
);
73 * \brief AES-ECB block encryption/decryption
75 * \param ctx AES context
76 * \param mode AES_ENCRYPT or AES_DECRYPT
77 * \param input 16-byte input block
78 * \param output 16-byte output block
80 void aes_crypt_ecb(aes_context
* ctx
,
82 const unsigned char input
[16],
83 unsigned char output
[16]);
86 * \brief AES-CBC buffer encryption/decryption
88 * \param ctx AES context
89 * \param mode AES_ENCRYPT or AES_DECRYPT
90 * \param length length of the input data
91 * \param iv initialization vector (updated after use)
92 * \param input buffer holding the input data
93 * \param output buffer holding the output data
95 void aes_crypt_cbc(aes_context
* ctx
,
99 const unsigned char *input
,
100 unsigned char *output
);
103 * \brief AES-CFB128 buffer encryption/decryption
105 * \param ctx AES context
106 * \param mode AES_ENCRYPT or AES_DECRYPT
107 * \param length length of the input data
108 * \param iv_off offset in IV (updated after use)
109 * \param iv initialization vector (updated after use)
110 * \param input buffer holding the input data
111 * \param output buffer holding the output data
113 void aes_crypt_cfb128(aes_context
* ctx
,
117 unsigned char iv
[16],
118 const unsigned char *input
,
119 unsigned char *output
);
122 * \brief Checkup routine
124 * \return 0 if successful, or 1 if the test failed
126 int aes_self_test(int verbose
);