]>
git.saurik.com Git - apple/xnu.git/blob - bsd/crypto/aes/aes.h
2 ---------------------------------------------------------------------------
3 Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
7 The free distribution and use of this software in both source and binary
8 form is allowed (with or without changes) provided that:
10 1. distributions of this source code include the above copyright
11 notice, this list of conditions and the following disclaimer;
13 2. distributions in binary form include the above copyright
14 notice, this list of conditions and the following disclaimer
15 in the documentation and/or other associated materials;
17 3. the copyright holder's name is not used to endorse products
18 built using this software without specific written permission.
20 ALTERNATIVELY, provided that this notice is retained in full, this product
21 may be distributed under the terms of the GNU General Public License (GPL),
22 in which case the provisions of the GPL apply INSTEAD OF those given above.
26 This software is provided 'as is' with no explicit or implied warranties
27 in respect of its properties, including, but not limited to, correctness
28 and/or fitness for purpose.
29 ---------------------------------------------------------------------------
32 This file contains the definitions required to use AES in C. See aesopt.h
33 for optimisation details.
40 #if defined(__cplusplus)
45 #define AES_128 /* define if AES with 128 bit keys is needed */
46 #define AES_192 /* define if AES with 192 bit keys is needed */
47 #define AES_256 /* define if AES with 256 bit keys is needed */
48 #define AES_VAR /* define if a variable key size is needed */
49 #define AES_MODES /* define if support is needed for modes */
51 /* The following must also be set in assembler files if being used */
53 #define AES_ENCRYPT /* if support for encryption is needed */
54 #define AES_DECRYPT /* if support for decryption is needed */
55 #define AES_ERR_CHK /* for parameter checks & error return codes */
56 #define AES_REV_DKS /* define to reverse decryption key schedule */
58 #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
59 #define N_COLS 4 /* the number of columns in the state */
61 typedef unsigned long uint_32t
;
62 typedef unsigned char uint_8t
;
63 typedef unsigned short uint_16t
;
64 typedef unsigned char aes_08t
;
65 typedef unsigned long aes_32t
;
70 /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
71 /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
72 /* or 44, 52 or 60 32-bit words. */
74 #if defined( AES_VAR ) || defined( AES_256 )
76 #elif defined( AES_192 )
84 /* the character array 'inf' in the following structures is used */
85 /* to hold AES context information. This AES code uses cx->inf.b[0] */
86 /* to hold the number of rounds multiplied by 16. The other three */
87 /* elements can be used by code that implements additional modes */
89 #if defined (__i386__)
91 #if defined( AES_ERR_CHK )
92 #define aes_rval int_ret
94 #define aes_rval void_ret
103 { uint_32t ks
[KS_LENGTH
];
108 { uint_32t ks
[KS_LENGTH
];
114 #if defined( AES_ERR_CHK )
122 #define aes_rval aes_ret
125 { aes_32t ks
[KS_LENGTH
];
130 { aes_32t ks
[KS_LENGTH
];
138 aes_decrypt_ctx decrypt
;
139 aes_encrypt_ctx encrypt
;
143 /* implemented in case of wrong call for fixed tables */
148 /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
149 /* those in the range 128 <= key_len <= 256 are given in bits */
151 #if defined( AES_ENCRYPT )
153 #if defined(AES_128) || defined(AES_VAR)
154 aes_rval
aes_encrypt_key128(const unsigned char *key
, aes_encrypt_ctx cx
[1]);
157 #if defined(AES_192) || defined(AES_VAR)
158 aes_rval
aes_encrypt_key192(const unsigned char *key
, aes_encrypt_ctx cx
[1]);
161 #if defined(AES_256) || defined(AES_VAR)
162 aes_rval
aes_encrypt_key256(const unsigned char *key
, aes_encrypt_ctx cx
[1]);
166 aes_rval
aes_encrypt_key(const unsigned char *key
, int key_len
, aes_encrypt_ctx cx
[1]);
169 #if defined (__i386__)
170 aes_rval
aes_encrypt(const unsigned char *in
, unsigned char *out
, const aes_encrypt_ctx cx
[1]);
173 aes_rval
aes_encrypt_cbc(const unsigned char *in_blk
, const unsigned char *in_iv
, unsigned int num_blk
,
174 unsigned char *out_blk
, const aes_encrypt_ctx cx
[1]);
178 #if defined( AES_DECRYPT )
180 #if defined(AES_128) || defined(AES_VAR)
181 aes_rval
aes_decrypt_key128(const unsigned char *key
, aes_decrypt_ctx cx
[1]);
184 #if defined(AES_192) || defined(AES_VAR)
185 aes_rval
aes_decrypt_key192(const unsigned char *key
, aes_decrypt_ctx cx
[1]);
188 #if defined(AES_256) || defined(AES_VAR)
189 aes_rval
aes_decrypt_key256(const unsigned char *key
, aes_decrypt_ctx cx
[1]);
193 aes_rval
aes_decrypt_key(const unsigned char *key
, int key_len
, aes_decrypt_ctx cx
[1]);
196 #if defined (__i386__)
197 aes_rval
aes_decrypt(const unsigned char *in
, unsigned char *out
, const aes_decrypt_ctx cx
[1]);
200 aes_rval
aes_decrypt_cbc(const unsigned char *in_blk
, const unsigned char *in_iv
, unsigned int num_blk
,
201 unsigned char *out_blk
, const aes_decrypt_ctx cx
[1]);
207 #if defined(__cplusplus)