diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/aesGladman/sha1.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-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/sha1.cpp | 474 |
1 files changed, 237 insertions, 237 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/aesGladman/sha1.cpp b/libraries/irrlicht-1.8/source/Irrlicht/aesGladman/sha1.cpp index 8a91768..3ebb509 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/aesGladman/sha1.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/aesGladman/sha1.cpp | |||
@@ -1,237 +1,237 @@ | |||
1 | /* | 1 | /* |
2 | --------------------------------------------------------------------------- | 2 | --------------------------------------------------------------------------- |
3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. | 3 | Copyright (c) 2002, 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 | This is a byte oriented version of SHA1 that operates on arrays of bytes | 33 | This is a byte oriented version of SHA1 that operates on arrays of bytes |
34 | stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor | 34 | stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include <string.h> /* for memcpy() etc. */ | 37 | #include <string.h> /* for memcpy() etc. */ |
38 | #include <stdlib.h> /* for _lrotl with VC++ */ | 38 | #include <stdlib.h> /* for _lrotl with VC++ */ |
39 | 39 | ||
40 | #include "sha1.h" | 40 | #include "sha1.h" |
41 | #include "../os.h" | 41 | #include "../os.h" |
42 | 42 | ||
43 | /* | 43 | /* |
44 | To obtain the highest speed on processors with 32-bit words, this code | 44 | To obtain the highest speed on processors with 32-bit words, this code |
45 | needs to determine the order in which bytes are packed into such words. | 45 | needs to determine the order in which bytes are packed into such words. |
46 | The following block of code is an attempt to capture the most obvious | 46 | The following block of code is an attempt to capture the most obvious |
47 | ways in which various environemnts specify their endian definitions. | 47 | ways in which various environemnts specify their endian definitions. |
48 | It may well fail, in which case the definitions will need to be set by | 48 | It may well fail, in which case the definitions will need to be set by |
49 | editing at the points marked **** EDIT HERE IF NECESSARY **** below. | 49 | editing at the points marked **** EDIT HERE IF NECESSARY **** below. |
50 | */ | 50 | */ |
51 | 51 | ||
52 | /* BYTE ORDER IN 32-BIT WORDS | 52 | /* BYTE ORDER IN 32-BIT WORDS |
53 | 53 | ||
54 | To obtain the highest speed on processors with 32-bit words, this code | 54 | To obtain the highest speed on processors with 32-bit words, this code |
55 | needs to determine the byte order of the target machine. The following | 55 | needs to determine the byte order of the target machine. The following |
56 | block of code is an attempt to capture the most obvious ways in which | 56 | block of code is an attempt to capture the most obvious ways in which |
57 | various environemnts define byte order. It may well fail, in which case | 57 | various environemnts define byte order. It may well fail, in which case |
58 | the definitions will need to be set by editing at the points marked | 58 | the definitions will need to be set by editing at the points marked |
59 | **** EDIT HERE IF NECESSARY **** below. My thanks to Peter Gutmann for | 59 | **** EDIT HERE IF NECESSARY **** below. My thanks to Peter Gutmann for |
60 | some of these defines (from cryptlib). | 60 | some of these defines (from cryptlib). |
61 | */ | 61 | */ |
62 | 62 | ||
63 | #define BRG_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ | 63 | #define BRG_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ |
64 | #define BRG_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ | 64 | #define BRG_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ |
65 | 65 | ||
66 | #ifdef __BIG_ENDIAN__ | 66 | #ifdef __BIG_ENDIAN__ |
67 | #define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN | 67 | #define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN |
68 | #else | 68 | #else |
69 | #define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN | 69 | #define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) | 72 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) |
73 | 73 | ||
74 | #if (PLATFORM_BYTE_ORDER == BRG_BIG_ENDIAN) | 74 | #if (PLATFORM_BYTE_ORDER == BRG_BIG_ENDIAN) |
75 | #define swap_b32(x) (x) | 75 | #define swap_b32(x) (x) |
76 | #else | 76 | #else |
77 | #define swap_b32(x) irr::os::Byteswap::byteswap(x) | 77 | #define swap_b32(x) irr::os::Byteswap::byteswap(x) |
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) | 80 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) |
81 | 81 | ||
82 | #if 1 | 82 | #if 1 |
83 | 83 | ||
84 | #define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) | 84 | #define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) |
85 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) | 85 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) |
86 | #define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) | 86 | #define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) |
87 | 87 | ||
88 | #else /* Discovered Rich Schroeppel and Colin Plumb */ | 88 | #else /* Discovered Rich Schroeppel and Colin Plumb */ |
89 | 89 | ||
90 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) | 90 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) |
91 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) | 91 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) |
92 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) | 92 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) |
93 | 93 | ||
94 | #endif | 94 | #endif |
95 | 95 | ||
96 | /* A normal version as set out in the FIPS */ | 96 | /* A normal version as set out in the FIPS */ |
97 | 97 | ||
98 | #define rnd(f,k) \ | 98 | #define rnd(f,k) \ |
99 | t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \ | 99 | t = a; a = rotl32(a,5) + f(b,c,d) + e + k + w[i]; \ |
100 | e = d; d = c; c = rotl32(b, 30); b = t | 100 | e = d; d = c; c = rotl32(b, 30); b = t |
101 | 101 | ||
102 | void sha1_compile(sha1_ctx ctx[1]) | 102 | void sha1_compile(sha1_ctx ctx[1]) |
103 | { sha1_32t w[80], i, a, b, c, d, e, t; | 103 | { sha1_32t w[80], i, a, b, c, d, e, t; |
104 | 104 | ||
105 | /* note that words are compiled from the buffer into 32-bit */ | 105 | /* note that words are compiled from the buffer into 32-bit */ |
106 | /* words in big-endian order so an order reversal is needed */ | 106 | /* words in big-endian order so an order reversal is needed */ |
107 | /* here on little endian machines */ | 107 | /* here on little endian machines */ |
108 | for(i = 0; i < SHA1_BLOCK_SIZE / 4; ++i) | 108 | for(i = 0; i < SHA1_BLOCK_SIZE / 4; ++i) |
109 | w[i] = swap_b32(ctx->wbuf[i]); | 109 | w[i] = swap_b32(ctx->wbuf[i]); |
110 | 110 | ||
111 | for(i = SHA1_BLOCK_SIZE / 4; i < 80; ++i) | 111 | for(i = SHA1_BLOCK_SIZE / 4; i < 80; ++i) |
112 | w[i] = rotl32(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1); | 112 | w[i] = rotl32(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1); |
113 | 113 | ||
114 | a = ctx->hash[0]; | 114 | a = ctx->hash[0]; |
115 | b = ctx->hash[1]; | 115 | b = ctx->hash[1]; |
116 | c = ctx->hash[2]; | 116 | c = ctx->hash[2]; |
117 | d = ctx->hash[3]; | 117 | d = ctx->hash[3]; |
118 | e = ctx->hash[4]; | 118 | e = ctx->hash[4]; |
119 | 119 | ||
120 | for(i = 0; i < 20; ++i) | 120 | for(i = 0; i < 20; ++i) |
121 | { | 121 | { |
122 | rnd(ch, 0x5a827999); | 122 | rnd(ch, 0x5a827999); |
123 | } | 123 | } |
124 | 124 | ||
125 | for(i = 20; i < 40; ++i) | 125 | for(i = 20; i < 40; ++i) |
126 | { | 126 | { |
127 | rnd(parity, 0x6ed9eba1); | 127 | rnd(parity, 0x6ed9eba1); |
128 | } | 128 | } |
129 | 129 | ||
130 | for(i = 40; i < 60; ++i) | 130 | for(i = 40; i < 60; ++i) |
131 | { | 131 | { |
132 | rnd(maj, 0x8f1bbcdc); | 132 | rnd(maj, 0x8f1bbcdc); |
133 | } | 133 | } |
134 | 134 | ||
135 | for(i = 60; i < 80; ++i) | 135 | for(i = 60; i < 80; ++i) |
136 | { | 136 | { |
137 | rnd(parity, 0xca62c1d6); | 137 | rnd(parity, 0xca62c1d6); |
138 | } | 138 | } |
139 | 139 | ||
140 | ctx->hash[0] += a; | 140 | ctx->hash[0] += a; |
141 | ctx->hash[1] += b; | 141 | ctx->hash[1] += b; |
142 | ctx->hash[2] += c; | 142 | ctx->hash[2] += c; |
143 | ctx->hash[3] += d; | 143 | ctx->hash[3] += d; |
144 | ctx->hash[4] += e; | 144 | ctx->hash[4] += e; |
145 | } | 145 | } |
146 | 146 | ||
147 | void sha1_begin(sha1_ctx ctx[1]) | 147 | void sha1_begin(sha1_ctx ctx[1]) |
148 | { | 148 | { |
149 | ctx->count[0] = ctx->count[1] = 0; | 149 | ctx->count[0] = ctx->count[1] = 0; |
150 | ctx->hash[0] = 0x67452301; | 150 | ctx->hash[0] = 0x67452301; |
151 | ctx->hash[1] = 0xefcdab89; | 151 | ctx->hash[1] = 0xefcdab89; |
152 | ctx->hash[2] = 0x98badcfe; | 152 | ctx->hash[2] = 0x98badcfe; |
153 | ctx->hash[3] = 0x10325476; | 153 | ctx->hash[3] = 0x10325476; |
154 | ctx->hash[4] = 0xc3d2e1f0; | 154 | ctx->hash[4] = 0xc3d2e1f0; |
155 | } | 155 | } |
156 | 156 | ||
157 | /* SHA1 hash data in an array of bytes into hash buffer and */ | 157 | /* SHA1 hash data in an array of bytes into hash buffer and */ |
158 | /* call the hash_compile function as required. */ | 158 | /* call the hash_compile function as required. */ |
159 | 159 | ||
160 | void sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) | 160 | void sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) |
161 | { sha1_32t pos = (sha1_32t)(ctx->count[0] & SHA1_MASK), | 161 | { sha1_32t pos = (sha1_32t)(ctx->count[0] & SHA1_MASK), |
162 | space = SHA1_BLOCK_SIZE - pos; | 162 | space = SHA1_BLOCK_SIZE - pos; |
163 | const unsigned char *sp = data; | 163 | const unsigned char *sp = data; |
164 | 164 | ||
165 | if((ctx->count[0] += len) < len) | 165 | if((ctx->count[0] += len) < len) |
166 | ++(ctx->count[1]); | 166 | ++(ctx->count[1]); |
167 | 167 | ||
168 | while(len >= space) /* tranfer whole blocks if possible */ | 168 | while(len >= space) /* tranfer whole blocks if possible */ |
169 | { | 169 | { |
170 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, space); | 170 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, space); |
171 | sp += space; len -= space; space = SHA1_BLOCK_SIZE; pos = 0; | 171 | sp += space; len -= space; space = SHA1_BLOCK_SIZE; pos = 0; |
172 | sha1_compile(ctx); | 172 | sha1_compile(ctx); |
173 | } | 173 | } |
174 | 174 | ||
175 | /*lint -e{803} conceivable data overrun */ | 175 | /*lint -e{803} conceivable data overrun */ |
176 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, len); | 176 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, len); |
177 | } | 177 | } |
178 | 178 | ||
179 | /* SHA1 final padding and digest calculation */ | 179 | /* SHA1 final padding and digest calculation */ |
180 | 180 | ||
181 | #if (PLATFORM_BYTE_ORDER == BRG_LITTLE_ENDIAN) | 181 | #if (PLATFORM_BYTE_ORDER == BRG_LITTLE_ENDIAN) |
182 | static sha1_32t mask[4] = | 182 | static sha1_32t mask[4] = |
183 | { 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff }; | 183 | { 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff }; |
184 | static sha1_32t bits[4] = | 184 | static sha1_32t bits[4] = |
185 | { 0x00000080, 0x00008000, 0x00800000, 0x80000000 }; | 185 | { 0x00000080, 0x00008000, 0x00800000, 0x80000000 }; |
186 | #else | 186 | #else |
187 | static sha1_32t mask[4] = | 187 | static sha1_32t mask[4] = |
188 | { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 }; | 188 | { 0x00000000, 0xff000000, 0xffff0000, 0xffffff00 }; |
189 | static sha1_32t bits[4] = | 189 | static sha1_32t bits[4] = |
190 | { 0x80000000, 0x00800000, 0x00008000, 0x00000080 }; | 190 | { 0x80000000, 0x00800000, 0x00008000, 0x00000080 }; |
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | void sha1_end(unsigned char hval[], sha1_ctx ctx[1]) | 193 | void sha1_end(unsigned char hval[], sha1_ctx ctx[1]) |
194 | { sha1_32t i = (sha1_32t)(ctx->count[0] & SHA1_MASK); | 194 | { sha1_32t i = (sha1_32t)(ctx->count[0] & SHA1_MASK); |
195 | 195 | ||
196 | /* mask out the rest of any partial 32-bit word and then set */ | 196 | /* mask out the rest of any partial 32-bit word and then set */ |
197 | /* the next byte to 0x80. On big-endian machines any bytes in */ | 197 | /* the next byte to 0x80. On big-endian machines any bytes in */ |
198 | /* the buffer will be at the top end of 32 bit words, on little */ | 198 | /* the buffer will be at the top end of 32 bit words, on little */ |
199 | /* endian machines they will be at the bottom. Hence the AND */ | 199 | /* endian machines they will be at the bottom. Hence the AND */ |
200 | /* and OR masks above are reversed for little endian systems */ | 200 | /* and OR masks above are reversed for little endian systems */ |
201 | /* Note that we can always add the first padding byte at this */ | 201 | /* Note that we can always add the first padding byte at this */ |
202 | /* point because the buffer always has at least one empty slot */ | 202 | /* point because the buffer always has at least one empty slot */ |
203 | ctx->wbuf[i >> 2] = (ctx->wbuf[i >> 2] & mask[i & 3]) | bits[i & 3]; | 203 | ctx->wbuf[i >> 2] = (ctx->wbuf[i >> 2] & mask[i & 3]) | bits[i & 3]; |
204 | 204 | ||
205 | /* we need 9 or more empty positions, one for the padding byte */ | 205 | /* we need 9 or more empty positions, one for the padding byte */ |
206 | /* (above) and eight for the length count. If there is not */ | 206 | /* (above) and eight for the length count. If there is not */ |
207 | /* enough space pad and empty the buffer */ | 207 | /* enough space pad and empty the buffer */ |
208 | if(i > SHA1_BLOCK_SIZE - 9) | 208 | if(i > SHA1_BLOCK_SIZE - 9) |
209 | { | 209 | { |
210 | if(i < 60) ctx->wbuf[15] = 0; | 210 | if(i < 60) ctx->wbuf[15] = 0; |
211 | sha1_compile(ctx); | 211 | sha1_compile(ctx); |
212 | i = 0; | 212 | i = 0; |
213 | } | 213 | } |
214 | else /* compute a word index for the empty buffer positions */ | 214 | else /* compute a word index for the empty buffer positions */ |
215 | i = (i >> 2) + 1; | 215 | i = (i >> 2) + 1; |
216 | 216 | ||
217 | while(i < 14) /* and zero pad all but last two positions */ | 217 | while(i < 14) /* and zero pad all but last two positions */ |
218 | ctx->wbuf[i++] = 0; | 218 | ctx->wbuf[i++] = 0; |
219 | 219 | ||
220 | /* assemble the eight byte counter in in big-endian format */ | 220 | /* assemble the eight byte counter in in big-endian format */ |
221 | ctx->wbuf[14] = swap_b32((ctx->count[1] << 3) | (ctx->count[0] >> 29)); | 221 | ctx->wbuf[14] = swap_b32((ctx->count[1] << 3) | (ctx->count[0] >> 29)); |
222 | ctx->wbuf[15] = swap_b32(ctx->count[0] << 3); | 222 | ctx->wbuf[15] = swap_b32(ctx->count[0] << 3); |
223 | 223 | ||
224 | sha1_compile(ctx); | 224 | sha1_compile(ctx); |
225 | 225 | ||
226 | /* extract the hash value as bytes in case the hash buffer is */ | 226 | /* extract the hash value as bytes in case the hash buffer is */ |
227 | /* misaligned for 32-bit words */ | 227 | /* misaligned for 32-bit words */ |
228 | for(i = 0; i < SHA1_DIGEST_SIZE; ++i) | 228 | for(i = 0; i < SHA1_DIGEST_SIZE; ++i) |
229 | hval[i] = (unsigned char)(ctx->hash[i >> 2] >> (8 * (~i & 3))); | 229 | hval[i] = (unsigned char)(ctx->hash[i >> 2] >> (8 * (~i & 3))); |
230 | } | 230 | } |
231 | 231 | ||
232 | void sha1(unsigned char hval[], const unsigned char data[], unsigned long len) | 232 | void sha1(unsigned char hval[], const unsigned char data[], unsigned long len) |
233 | { sha1_ctx cx[1]; | 233 | { sha1_ctx cx[1]; |
234 | 234 | ||
235 | sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); | 235 | sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); |
236 | } | 236 | } |
237 | 237 | ||