diff options
author | David Walter Seikel | 2014-01-13 19:47:58 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-01-13 19:47:58 +1000 |
commit | f9158592e1478b2013afc7041d9ed041cf2d2f4a (patch) | |
tree | b16e389d7988700e21b4c9741044cefa536dcbae /libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/aestab.cpp | |
parent | Libraries readme updated with change markers and more of the Irrlicht changes. (diff) | |
download | SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.zip SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.gz SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.bz2 SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.xz |
Update Irrlicht to 1.8.1. Include actual change markers this time. lol
Diffstat (limited to 'libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/aestab.cpp')
-rw-r--r-- | libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/aestab.cpp | 223 |
1 files changed, 223 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/aestab.cpp b/libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/aestab.cpp new file mode 100644 index 0000000..e94aa76 --- /dev/null +++ b/libraries/irrlicht-1.8.1/source/Irrlicht/aesGladman/aestab.cpp | |||
@@ -0,0 +1,223 @@ | |||
1 | /* | ||
2 | --------------------------------------------------------------------------- | ||
3 | Copyright (c) 2003, Dr Brian Gladman < >, Worcester, UK. | ||
4 | All rights reserved. | ||
5 | |||
6 | LICENSE TERMS | ||
7 | |||
8 | The free distribution and use of this software in both source and binary | ||
9 | form is allowed (with or without changes) provided that: | ||
10 | |||
11 | 1. distributions of this source code include the above copyright | ||
12 | notice, this list of conditions and the following disclaimer; | ||
13 | |||
14 | 2. distributions in binary form include the above copyright | ||
15 | notice, this list of conditions and the following disclaimer | ||
16 | in the documentation and/or other associated materials; | ||
17 | |||
18 | 3. the copyright holder's name is not used to endorse products | ||
19 | built using this software without specific written permission. | ||
20 | |||
21 | ALTERNATIVELY, provided that this notice is retained in full, this product | ||
22 | may be distributed under the terms of the GNU General Public License (GPL), | ||
23 | in which case the provisions of the GPL apply INSTEAD OF those given above. | ||
24 | |||
25 | DISCLAIMER | ||
26 | |||
27 | This software is provided 'as is' with no explicit or implied warranties | ||
28 | in respect of its properties, including, but not limited to, correctness | ||
29 | and/or fitness for purpose. | ||
30 | --------------------------------------------------------------------------- | ||
31 | Issue Date: 26/08/2003 | ||
32 | |||
33 | */ | ||
34 | |||
35 | #define DO_TABLES | ||
36 | |||
37 | #include "aesopt.h" | ||
38 | |||
39 | #if defined(FIXED_TABLES) | ||
40 | |||
41 | /* implemented in case of wrong call for fixed tables */ | ||
42 | |||
43 | void gen_tabs(void) | ||
44 | { | ||
45 | } | ||
46 | |||
47 | #else /* dynamic table generation */ | ||
48 | |||
49 | #if !defined(FF_TABLES) | ||
50 | |||
51 | /* Generate the tables for the dynamic table option | ||
52 | |||
53 | It will generally be sensible to use tables to compute finite | ||
54 | field multiplies and inverses but where memory is scarse this | ||
55 | code might sometimes be better. But it only has effect during | ||
56 | initialisation so its pretty unimportant in overall terms. | ||
57 | */ | ||
58 | |||
59 | /* return 2 ^ (n - 1) where n is the bit number of the highest bit | ||
60 | set in x with x in the range 1 < x < 0x00000200. This form is | ||
61 | used so that locals within fi can be bytes rather than words | ||
62 | */ | ||
63 | |||
64 | static aes_08t hibit(const aes_32t x) | ||
65 | { aes_08t r = (aes_08t)((x >> 1) | (x >> 2)); | ||
66 | |||
67 | r |= (r >> 2); | ||
68 | r |= (r >> 4); | ||
69 | return (r + 1) >> 1; | ||
70 | } | ||
71 | |||
72 | /* return the inverse of the finite field element x */ | ||
73 | |||
74 | static aes_08t fi(const aes_08t x) | ||
75 | { aes_08t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; | ||
76 | |||
77 | if(x < 2) return x; | ||
78 | |||
79 | for(;;) | ||
80 | { | ||
81 | if(!n1) return v1; | ||
82 | |||
83 | while(n2 >= n1) | ||
84 | { | ||
85 | n2 /= n1; p2 ^= p1 * n2; v2 ^= v1 * n2; n2 = hibit(p2); | ||
86 | } | ||
87 | |||
88 | if(!n2) return v2; | ||
89 | |||
90 | while(n1 >= n2) | ||
91 | { | ||
92 | n1 /= n2; p1 ^= p2 * n1; v1 ^= v2 * n1; n1 = hibit(p1); | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | #endif | ||
98 | |||
99 | /* The forward and inverse affine transformations used in the S-box */ | ||
100 | |||
101 | #define fwd_affine(x) \ | ||
102 | (w = (aes_32t)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(aes_08t)(w^(w>>8))) | ||
103 | |||
104 | #define inv_affine(x) \ | ||
105 | (w = (aes_32t)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(aes_08t)(w^(w>>8))) | ||
106 | |||
107 | static int init = 0; | ||
108 | |||
109 | void gen_tabs(void) | ||
110 | { aes_32t i, w; | ||
111 | |||
112 | #if defined(FF_TABLES) | ||
113 | |||
114 | aes_08t pow[512], log[256]; | ||
115 | |||
116 | if(init) return; | ||
117 | /* log and power tables for GF(2^8) finite field with | ||
118 | WPOLY as modular polynomial - the simplest primitive | ||
119 | root is 0x03, used here to generate the tables | ||
120 | */ | ||
121 | |||
122 | i = 0; w = 1; | ||
123 | do | ||
124 | { | ||
125 | pow[i] = (aes_08t)w; | ||
126 | pow[i + 255] = (aes_08t)w; | ||
127 | log[w] = (aes_08t)i++; | ||
128 | w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0); | ||
129 | } | ||
130 | while (w != 1); | ||
131 | |||
132 | #else | ||
133 | if(init) return; | ||
134 | #endif | ||
135 | |||
136 | for(i = 0, w = 1; i < RC_LENGTH; ++i) | ||
137 | { | ||
138 | t_set(r,c)[i] = bytes2word(w, 0, 0, 0); | ||
139 | w = f2(w); | ||
140 | } | ||
141 | |||
142 | for(i = 0; i < 256; ++i) | ||
143 | { aes_08t b; | ||
144 | |||
145 | b = fwd_affine(fi((aes_08t)i)); | ||
146 | w = bytes2word(f2(b), b, b, f3(b)); | ||
147 | |||
148 | #ifdef SBX_SET | ||
149 | t_set(s,box)[i] = b; | ||
150 | #endif | ||
151 | |||
152 | #ifdef FT1_SET /* tables for a normal encryption round */ | ||
153 | t_set(f,n)[i] = w; | ||
154 | #endif | ||
155 | #ifdef FT4_SET | ||
156 | t_set(f,n)[0][i] = w; | ||
157 | t_set(f,n)[1][i] = upr(w,1); | ||
158 | t_set(f,n)[2][i] = upr(w,2); | ||
159 | t_set(f,n)[3][i] = upr(w,3); | ||
160 | #endif | ||
161 | w = bytes2word(b, 0, 0, 0); | ||
162 | |||
163 | #ifdef FL1_SET /* tables for last encryption round (may also */ | ||
164 | t_set(f,l)[i] = w; /* be used in the key schedule) */ | ||
165 | #endif | ||
166 | #ifdef FL4_SET | ||
167 | t_set(f,l)[0][i] = w; | ||
168 | t_set(f,l)[1][i] = upr(w,1); | ||
169 | t_set(f,l)[2][i] = upr(w,2); | ||
170 | t_set(f,l)[3][i] = upr(w,3); | ||
171 | #endif | ||
172 | |||
173 | #ifdef LS1_SET /* table for key schedule if t_set(f,l) above is */ | ||
174 | t_set(l,s)[i] = w; /* not of the required form */ | ||
175 | #endif | ||
176 | #ifdef LS4_SET | ||
177 | t_set(l,s)[0][i] = w; | ||
178 | t_set(l,s)[1][i] = upr(w,1); | ||
179 | t_set(l,s)[2][i] = upr(w,2); | ||
180 | t_set(l,s)[3][i] = upr(w,3); | ||
181 | #endif | ||
182 | |||
183 | b = fi(inv_affine((aes_08t)i)); | ||
184 | w = bytes2word(fe(b), f9(b), fd(b), fb(b)); | ||
185 | |||
186 | #ifdef IM1_SET /* tables for the inverse mix column operation */ | ||
187 | t_set(i,m)[b] = w; | ||
188 | #endif | ||
189 | #ifdef IM4_SET | ||
190 | t_set(i,m)[0][b] = w; | ||
191 | t_set(i,m)[1][b] = upr(w,1); | ||
192 | t_set(i,m)[2][b] = upr(w,2); | ||
193 | t_set(i,m)[3][b] = upr(w,3); | ||
194 | #endif | ||
195 | |||
196 | #ifdef ISB_SET | ||
197 | t_set(i,box)[i] = b; | ||
198 | #endif | ||
199 | #ifdef IT1_SET /* tables for a normal decryption round */ | ||
200 | t_set(i,n)[i] = w; | ||
201 | #endif | ||
202 | #ifdef IT4_SET | ||
203 | t_set(i,n)[0][i] = w; | ||
204 | t_set(i,n)[1][i] = upr(w,1); | ||
205 | t_set(i,n)[2][i] = upr(w,2); | ||
206 | t_set(i,n)[3][i] = upr(w,3); | ||
207 | #endif | ||
208 | w = bytes2word(b, 0, 0, 0); | ||
209 | #ifdef IL1_SET /* tables for last decryption round */ | ||
210 | t_set(i,l)[i] = w; | ||
211 | #endif | ||
212 | #ifdef IL4_SET | ||
213 | t_set(i,l)[0][i] = w; | ||
214 | t_set(i,l)[1][i] = upr(w,1); | ||
215 | t_set(i,l)[2][i] = upr(w,2); | ||
216 | t_set(i,l)[3][i] = upr(w,3); | ||
217 | #endif | ||
218 | } | ||
219 | init = 1; | ||
220 | } | ||
221 | |||
222 | #endif | ||
223 | |||