]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/aesGladman/aes.h
127c886ce43fa571a527a52c394685c5baf3e3ba
[irrlicht.git] / source / Irrlicht / aesGladman / aes.h
1 /*\r
2  ---------------------------------------------------------------------------\r
3  Copyright (c) 2003, Dr Brian Gladman <                 >, Worcester, UK.\r
4  All rights reserved.\r
5 \r
6  LICENSE TERMS\r
7 \r
8  The free distribution and use of this software in both source and binary\r
9  form is allowed (with or without changes) provided that:\r
10 \r
11    1. distributions of this source code include the above copyright\r
12       notice, this list of conditions and the following disclaimer;\r
13 \r
14    2. distributions in binary form include the above copyright\r
15       notice, this list of conditions and the following disclaimer\r
16       in the documentation and/or other associated materials;\r
17 \r
18    3. the copyright holder's name is not used to endorse products\r
19       built using this software without specific written permission.\r
20 \r
21  ALTERNATIVELY, provided that this notice is retained in full, this product\r
22  may be distributed under the terms of the GNU General Public License (GPL),\r
23  in which case the provisions of the GPL apply INSTEAD OF those given above.\r
24 \r
25  DISCLAIMER\r
26 \r
27  This software is provided 'as is' with no explicit or implied warranties\r
28  in respect of its properties, including, but not limited to, correctness\r
29  and/or fitness for purpose.\r
30  ---------------------------------------------------------------------------\r
31  Issue Date: 26/08/2003\r
32 \r
33  This file contains the definitions required to use AES in C. See aesopt.h\r
34  for optimisation details.\r
35 */\r
36 \r
37 #ifndef _AES_H\r
38 #define _AES_H\r
39 \r
40 #include "irrMath.h"\r
41 \r
42 #define AES_128     /* define if AES with 128 bit keys is needed    */\r
43 #define AES_192     /* define if AES with 192 bit keys is needed    */\r
44 #define AES_256     /* define if AES with 256 bit keys is needed    */\r
45 #define AES_VAR     /* define if a variable key size is needed      */\r
46 \r
47 /* The following must also be set in assembler files if being used  */\r
48 \r
49 #define AES_ENCRYPT /* if support for encryption is needed          */\r
50 #define AES_DECRYPT /* if support for decryption is needed          */\r
51 #define AES_ERR_CHK /* for parameter checks & error return codes    */\r
52 \r
53 typedef irr::u8 aes_08t;\r
54 typedef irr::u32 aes_32t;\r
55 \r
56 #define AES_BLOCK_SIZE  16  /* the AES block size in bytes          */\r
57 #define N_COLS           4  /* the number of columns in the state   */\r
58 \r
59 /* a maximum of 60 32-bit words are needed for the key schedule         */\r
60 #define KS_LENGTH       64\r
61 \r
62 #ifdef  AES_ERR_CHK\r
63 #define aes_ret     int\r
64 #define aes_good    0\r
65 #define aes_error  -1\r
66 #else\r
67 #define aes_ret     void\r
68 #endif\r
69 \r
70 #ifndef AES_DLL                 /* implement normal/DLL functions   */\r
71 #define aes_rval    aes_ret\r
72 #else\r
73 #define aes_rval    aes_ret __declspec(dllexport) _stdcall\r
74 #endif\r
75 \r
76 /* This routine must be called before first use if non-static       */\r
77 /* tables are being used                                            */\r
78 \r
79 void gen_tabs(void);\r
80 \r
81 /* The key length (klen) is input in bytes when it is in the range  */\r
82 /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */\r
83 \r
84 #ifdef  AES_ENCRYPT\r
85 \r
86 typedef struct  \r
87 {\r
88         aes_32t ks[KS_LENGTH];\r
89 } aes_encrypt_ctx;\r
90 \r
91 #if defined(AES_128) || defined(AES_VAR)\r
92 aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]);\r
93 #endif\r
94 \r
95 #if defined(AES_192) || defined(AES_VAR)\r
96 aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]);\r
97 #endif\r
98 \r
99 #if defined(AES_256) || defined(AES_VAR)\r
100 aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]);\r
101 #endif\r
102 \r
103 #if defined(AES_VAR)\r
104 aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx[1]);\r
105 #endif\r
106 \r
107 aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]);\r
108 #endif\r
109 \r
110 #ifdef AES_DECRYPT\r
111 \r
112 typedef struct  \r
113 {\r
114         aes_32t ks[KS_LENGTH];\r
115 } aes_decrypt_ctx;\r
116 \r
117 #if defined(AES_128) || defined(AES_VAR)\r
118 aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]);\r
119 #endif\r
120 \r
121 #if defined(AES_192) || defined(AES_VAR)\r
122 aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]);\r
123 #endif\r
124 \r
125 #if defined(AES_256) || defined(AES_VAR)\r
126 aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]);\r
127 #endif\r
128 \r
129 #if defined(AES_VAR)\r
130 aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]);\r
131 #endif\r
132 \r
133 aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]);\r
134 #endif\r
135 \r
136 #endif\r
137 \r