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