]>
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.
36 #if !defined( _AES_H )
39 /* This include is used to find 8 & 32 bit unsigned integer types */
40 #include <machine/limits.h>
42 #if defined(__cplusplus)
47 #define AES_128 /* define if AES with 128 bit keys is needed */
48 #define AES_192 /* define if AES with 192 bit keys is needed */
49 #define AES_256 /* define if AES with 256 bit keys is needed */
50 #define AES_VAR /* define if a variable key size is needed */
52 /* The following must also be set in assembler files if being used */
54 #define AES_ENCRYPT /* if support for encryption is needed */
55 #define AES_DECRYPT /* if support for decryption is needed */
56 //#define AES_ERR_CHK /* for parameter checks & error return codes */
58 #if UCHAR_MAX == 0xff /* an unsigned 8 bit type */
59 typedef unsigned char aes_08t
;
61 # error Please define aes_08t as an 8-bit unsigned integer type in aes.h
64 #if UINT_MAX == 4294967295 /* an unsigned 32 bit type */
65 typedef unsigned int aes_32t
;
66 #elif ULONG_MAX == 4294967295ul
67 typedef unsigned long aes_32t
;
69 # error Please define aes_32t as a 32-bit unsigned integer type in aes.h
72 #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
73 #define N_COLS 4 /* the number of columns in the state */
75 /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
76 /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
77 /* or 44, 52 or 60 32-bit words. For simplicity this code allocates */
78 /* the maximum 60 word array for the key schedule for all key sizes */
80 #if defined( AES_VAR ) || defined( AES_256 )
82 #elif defined( AES_192 )
88 #if defined( AES_ERR_CHK )
96 #if !defined( AES_DLL ) /* implement normal/DLL functions */
97 #define aes_rval aes_ret
99 #define aes_rval aes_ret __declspec(dllexport) _stdcall
103 { aes_32t ks
[KS_LENGTH
];
108 { aes_32t ks
[KS_LENGTH
];
114 aes_decrypt_ctx decrypt
;
115 aes_encrypt_ctx encrypt
;
119 /* This routine must be called before first use if non-static */
120 /* tables are being used */
124 /* The key length (klen) is input in bytes when it is in the range */
125 /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */
127 #if defined( AES_ENCRYPT )
129 #if defined(AES_128) || defined(AES_VAR)
130 aes_rval
aes_encrypt_key128(const unsigned char *in_key
, aes_encrypt_ctx cx
[1]);
133 #if defined(AES_192) || defined(AES_VAR)
134 aes_rval
aes_encrypt_key192(const unsigned char *in_key
, aes_encrypt_ctx cx
[1]);
137 #if defined(AES_256) || defined(AES_VAR)
138 aes_rval
aes_encrypt_key256(const unsigned char *in_key
, aes_encrypt_ctx cx
[1]);
142 aes_rval
aes_encrypt_key(const unsigned char *in_key
, int key_len
, aes_encrypt_ctx cx
[1]);
145 aes_rval
aes_encrypt_cbc(const unsigned char *in_blk
, const unsigned char *in_iv
, unsigned int num_blk
,
146 unsigned char *out_blk
, const aes_encrypt_ctx cx
[1]);
149 #if defined( AES_DECRYPT )
151 #if defined(AES_128) || defined(AES_VAR)
152 aes_rval
aes_decrypt_key128(const unsigned char *in_key
, aes_decrypt_ctx cx
[1]);
155 #if defined(AES_192) || defined(AES_VAR)
156 aes_rval
aes_decrypt_key192(const unsigned char *in_key
, aes_decrypt_ctx cx
[1]);
159 #if defined(AES_256) || defined(AES_VAR)
160 aes_rval
aes_decrypt_key256(const unsigned char *in_key
, aes_decrypt_ctx cx
[1]);
164 aes_rval
aes_decrypt_key(const unsigned char *in_key
, int key_len
, aes_decrypt_ctx cx
[1]);
167 aes_rval
aes_decrypt_cbc(const unsigned char *in_blk
, const unsigned char *in_iv
, unsigned int num_blk
,
168 unsigned char *out_blk
, const aes_decrypt_ctx cx
[1]);
171 #if defined(__cplusplus)