ssl_tls: fix format warning in ssl_parse_certificate() on x86_64
[tropicssl.git] / include / tropicssl / aes.h
blob9f3d350ce7d0ddfd3a4db1fe8e12808b48c56ab6
1 /**
2 * \file aes.h
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
6 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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
38 #define AES_ENCRYPT 1
39 #define AES_DECRYPT 0
41 /**
42 * \brief AES context structure
44 typedef struct {
45 int nr; /*!< number of rounds */
46 unsigned long *rk; /*!< AES round keys */
47 unsigned long buf[68]; /*!< unaligned data */
48 } aes_context;
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
54 /**
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);
63 /**
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);
72 /**
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,
81 int mode,
82 const unsigned char input[16],
83 unsigned char output[16]);
85 /**
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,
96 int mode,
97 int length,
98 unsigned char iv[16],
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,
114 int mode,
115 int length,
116 int *iv_off,
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);
128 #ifdef __cplusplus
130 #endif
131 #endif /* aes.h */