|
|
1.1 root 1: /*
2: ---------------------------------------------------------------------------
3: Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
4:
5: LICENSE TERMS
6:
7: The free distribution and use of this software in both source and binary
8: form is allowed (with or without changes) provided that:
9:
10: 1. distributions of this source code include the above copyright
11: notice, this list of conditions and the following disclaimer;
12:
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;
16:
17: 3. the copyright holder's name is not used to endorse products
18: built using this software without specific written permission.
19:
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.
23:
24: DISCLAIMER
25:
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: ---------------------------------------------------------------------------
1.1.1.3 ! root 30: Issue 1/08/2005
1.1 root 31:
32: This file contains the definitions required to use AES in C. See aesopt.h
33: for optimisation details.
34: */
35:
1.1.1.3 ! root 36: /* Adapted for TrueCrypt by the TrueCrypt Foundation */
! 37:
! 38: #ifndef _AES_H
1.1 root 39: #define _AES_H
40:
1.1.1.3 ! root 41: #ifndef EXIT_SUCCESS
! 42: #define EXIT_SUCCESS 0
! 43: #define EXIT_FAILURE 1
1.1.1.2 root 44: #endif
1.1 root 45:
1.1.1.3 ! root 46: typedef unsigned __int8 uint_8t;
! 47: typedef unsigned __int16 uint_16t;
! 48: typedef unsigned __int32 uint_32t;
! 49: typedef unsigned __int64 uint_64t;
! 50:
! 51: #define void_ret void
! 52: #define int_ret int
! 53:
1.1 root 54: #if defined(__cplusplus)
55: extern "C"
56: {
57: #endif
58:
59: #define AES_128 /* define if AES with 128 bit keys is needed */
60: #define AES_192 /* define if AES with 192 bit keys is needed */
61: #define AES_256 /* define if AES with 256 bit keys is needed */
62: #define AES_VAR /* define if a variable key size is needed */
1.1.1.3 ! root 63: #define AES_MODES /* define if support is needed for modes */
1.1 root 64:
65: /* The following must also be set in assembler files if being used */
66:
67: #define AES_ENCRYPT /* if support for encryption is needed */
68: #define AES_DECRYPT /* if support for decryption is needed */
69: #define AES_ERR_CHK /* for parameter checks & error return codes */
1.1.1.3 ! root 70: #define AES_REV_DKS /* define to reverse decryption key schedule */
1.1 root 71:
72: #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
73: #define N_COLS 4 /* the number of columns in the state */
74:
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 */
1.1.1.3 ! root 77: /* or 44, 52 or 60 32-bit words. */
1.1 root 78:
79: #if defined( AES_VAR ) || defined( AES_256 )
80: #define KS_LENGTH 60
81: #elif defined( AES_192 )
82: #define KS_LENGTH 52
83: #else
84: #define KS_LENGTH 44
85: #endif
86:
87: #if defined( AES_ERR_CHK )
1.1.1.3 ! root 88: #define aes_rval int_ret
1.1 root 89: #else
1.1.1.3 ! root 90: #define aes_rval void_ret
1.1 root 91: #endif
92:
1.1.1.3 ! root 93: /* the character array 'inf' in the following structures is used */
! 94: /* to hold AES context information. This AES code uses cx->inf.b[0] */
! 95: /* to hold the number of rounds multiplied by 16. The other three */
! 96: /* elements can be used by code that implements additional modes */
! 97:
! 98: typedef union
! 99: { uint_32t l;
! 100: uint_8t b[4];
! 101: } aes_inf;
1.1 root 102:
103: typedef struct
1.1.1.3 ! root 104: { uint_32t ks[KS_LENGTH];
! 105: aes_inf inf;
1.1 root 106: } aes_encrypt_ctx;
107:
108: typedef struct
1.1.1.3 ! root 109: { uint_32t ks[KS_LENGTH];
! 110: aes_inf inf;
1.1 root 111: } aes_decrypt_ctx;
112:
113: /* This routine must be called before first use if non-static */
114: /* tables are being used */
115:
1.1.1.3 ! root 116: aes_rval gen_tabs(void);
1.1 root 117:
1.1.1.3 ! root 118: /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
! 119: /* those in the range 128 <= key_len <= 256 are given in bits */
1.1 root 120:
121: #if defined( AES_ENCRYPT )
122:
123: #if defined(AES_128) || defined(AES_VAR)
1.1.1.3 ! root 124: aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
1.1 root 125: #endif
126:
127: #if defined(AES_192) || defined(AES_VAR)
1.1.1.3 ! root 128: aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);
1.1 root 129: #endif
130:
131: #if defined(AES_256) || defined(AES_VAR)
1.1.1.3 ! root 132: aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);
1.1 root 133: #endif
134:
135: #if defined(AES_VAR)
1.1.1.3 ! root 136: aes_rval _cdecl aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]);
1.1 root 137: #endif
138:
1.1.1.3 ! root 139: aes_rval _cdecl aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
! 140:
1.1 root 141: #endif
142:
143: #if defined( AES_DECRYPT )
144:
145: #if defined(AES_128) || defined(AES_VAR)
1.1.1.3 ! root 146: aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
1.1 root 147: #endif
148:
149: #if defined(AES_192) || defined(AES_VAR)
1.1.1.3 ! root 150: aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);
1.1 root 151: #endif
152:
153: #if defined(AES_256) || defined(AES_VAR)
1.1.1.3 ! root 154: aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);
1.1 root 155: #endif
156:
157: #if defined(AES_VAR)
1.1.1.3 ! root 158: aes_rval _cdecl aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]);
! 159: #endif
! 160:
! 161: aes_rval _cdecl aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
! 162:
1.1 root 163: #endif
164:
1.1.1.3 ! root 165: #if defined(AES_MODES)
! 166:
! 167: aes_rval aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
! 168: int len, const aes_encrypt_ctx cx[1]);
! 169:
! 170: aes_rval aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
! 171: int len, const aes_decrypt_ctx cx[1]);
! 172:
! 173: aes_rval aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf,
! 174: int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
! 175:
! 176: aes_rval aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf,
! 177: int len, unsigned char *iv, const aes_decrypt_ctx cx[1]);
! 178:
! 179: aes_rval aes_mode_reset(aes_encrypt_ctx cx[1]);
! 180:
! 181: aes_rval aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
! 182: int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
! 183:
! 184: aes_rval aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
! 185: int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
! 186:
! 187: #define aes_ofb_encrypt aes_ofb_crypt
! 188: #define aes_ofb_decrypt aes_ofb_crypt
! 189:
! 190: aes_rval aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf,
! 191: int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
! 192:
! 193: typedef void cbuf_inc(unsigned char *cbuf);
! 194:
! 195: #define aes_ctr_encrypt aes_ctr_crypt
! 196: #define aes_ctr_decrypt aes_ctr_crypt
! 197:
! 198: aes_rval aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
! 199: int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
! 200:
1.1 root 201: #endif
202:
203: #if defined(__cplusplus)
204: }
205: #endif
206:
207: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.