]>
git.saurik.com Git - apple/xnu.git/blob - bsd/crypto/aes/aes.h
49c845da6ef406335b95682e3f01bc89a3619e67
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 int uint_32t
;
62 typedef unsigned char uint_8t
;
63 typedef unsigned short uint_16t
;
64 typedef unsigned char aes_08t
;
65 typedef unsigned int 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 )
83 #if 0 // defined (__i386__) || defined (__x86_64__)
86 looks like no other code for (i386/x86_64) is using the following definitions any more.
87 I comment this out, so the C code in the directory gen/ can be used to compile for test/development purpose.
88 Note : this is not going to change anything in the i386/x86_64 kernel.
89 (source code in i386/, mostly in assembly, does not reference to this header file.)
94 /* the character array 'inf' in the following structures is used */
95 /* to hold AES context information. This AES code uses cx->inf.b[0] */
96 /* to hold the number of rounds multiplied by 16. The other three */
97 /* elements can be used by code that implements additional modes */
99 #if defined( AES_ERR_CHK )
100 #define aes_rval int_ret
102 #define aes_rval void_ret
111 { uint_32t ks
[KS_LENGTH
];
116 { uint_32t ks
[KS_LENGTH
];
122 #if defined( AES_ERR_CHK )
130 #define aes_rval aes_ret
133 { aes_32t ks
[KS_LENGTH
];
138 { aes_32t ks
[KS_LENGTH
];
146 aes_decrypt_ctx decrypt
;
147 aes_encrypt_ctx encrypt
;
151 /* implemented in case of wrong call for fixed tables */
156 /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
157 /* those in the range 128 <= key_len <= 256 are given in bits */
159 #if defined( AES_ENCRYPT )
161 #if defined(AES_128) || defined(AES_VAR)
162 aes_rval
aes_encrypt_key128(const unsigned char *key
, aes_encrypt_ctx cx
[1]);
165 #if defined(AES_192) || defined(AES_VAR)
166 aes_rval
aes_encrypt_key192(const unsigned char *key
, aes_encrypt_ctx cx
[1]);
169 #if defined(AES_256) || defined(AES_VAR)
170 aes_rval
aes_encrypt_key256(const unsigned char *key
, aes_encrypt_ctx cx
[1]);
174 aes_rval
aes_encrypt_key(const unsigned char *key
, int key_len
, aes_encrypt_ctx cx
[1]);
177 #if defined (__i386__) || defined (__x86_64__)
178 aes_rval
aes_encrypt(const unsigned char *in
, unsigned char *out
, const aes_encrypt_ctx cx
[1]);
181 aes_rval
aes_encrypt_cbc(const unsigned char *in_blk
, const unsigned char *in_iv
, unsigned int num_blk
,
182 unsigned char *out_blk
, const aes_encrypt_ctx cx
[1]);
186 #if defined( AES_DECRYPT )
188 #if defined(AES_128) || defined(AES_VAR)
189 aes_rval
aes_decrypt_key128(const unsigned char *key
, aes_decrypt_ctx cx
[1]);
192 #if defined(AES_192) || defined(AES_VAR)
193 aes_rval
aes_decrypt_key192(const unsigned char *key
, aes_decrypt_ctx cx
[1]);
196 #if defined(AES_256) || defined(AES_VAR)
197 aes_rval
aes_decrypt_key256(const unsigned char *key
, aes_decrypt_ctx cx
[1]);
201 aes_rval
aes_decrypt_key(const unsigned char *key
, int key_len
, aes_decrypt_ctx cx
[1]);
204 #if defined (__i386__) || defined (__x86_64__)
205 aes_rval
aes_decrypt(const unsigned char *in
, unsigned char *out
, const aes_decrypt_ctx cx
[1]);
208 aes_rval
aes_decrypt_cbc(const unsigned char *in_blk
, const unsigned char *in_iv
, unsigned int num_blk
,
209 unsigned char *out_blk
, const aes_decrypt_ctx cx
[1]);
215 #if defined(__cplusplus)