diff options
author | Jacek Antonelli | 2008-08-15 23:45:04 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:04 -0500 |
commit | 117e22047c5752352342d64e3fb7ce00a4eb8113 (patch) | |
tree | e32de2cfba0dda8705ae528fcd1fbe23ba075685 /linden/indra/llmath/llmd5.cpp | |
parent | Second Life viewer sources 1.18.0.6 (diff) | |
download | meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.zip meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.tar.gz meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.tar.bz2 meta-impy-117e22047c5752352342d64e3fb7ce00a4eb8113.tar.xz |
Second Life viewer sources 1.18.1.2
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmath/llmd5.cpp | 111 |
1 files changed, 45 insertions, 66 deletions
diff --git a/linden/indra/llmath/llmd5.cpp b/linden/indra/llmath/llmd5.cpp index aad4617..1a8630c 100644 --- a/linden/indra/llmath/llmd5.cpp +++ b/linden/indra/llmath/llmd5.cpp | |||
@@ -83,6 +83,9 @@ documentation and/or software. | |||
83 | #include <fstream> | 83 | #include <fstream> |
84 | #include <iostream> | 84 | #include <iostream> |
85 | 85 | ||
86 | // how many bytes to grab at a time when checking files | ||
87 | const int LLMD5::BLOCK_LEN = 4096; | ||
88 | |||
86 | 89 | ||
87 | // LLMD5 simple initialization method | 90 | // LLMD5 simple initialization method |
88 | 91 | ||
@@ -156,10 +159,10 @@ void LLMD5::update (const uint1 *input, const uint4 input_length) { | |||
156 | 159 | ||
157 | void LLMD5::update(FILE* file){ | 160 | void LLMD5::update(FILE* file){ |
158 | 161 | ||
159 | unsigned char buffer[1024]; /* Flawfinder: ignore */ | 162 | unsigned char buffer[BLOCK_LEN]; /* Flawfinder: ignore */ |
160 | int len; | 163 | int len; |
161 | 164 | ||
162 | while ( (len=(int)fread(buffer, 1, 1024, file)) ) | 165 | while ( (len=(int)fread(buffer, 1, BLOCK_LEN, file)) ) |
163 | update(buffer, len); | 166 | update(buffer, len); |
164 | 167 | ||
165 | fclose (file); | 168 | fclose (file); |
@@ -176,11 +179,11 @@ void LLMD5::update(FILE* file){ | |||
176 | 179 | ||
177 | void LLMD5::update(std::istream& stream){ | 180 | void LLMD5::update(std::istream& stream){ |
178 | 181 | ||
179 | unsigned char buffer[1024]; /* Flawfinder: ignore */ | 182 | unsigned char buffer[BLOCK_LEN]; /* Flawfinder: ignore */ |
180 | int len; | 183 | int len; |
181 | 184 | ||
182 | while (stream.good()){ | 185 | while (stream.good()){ |
183 | stream.read( (char*)buffer, 1024); /* Flawfinder: ignore */ // note that return value of read is unusable. | 186 | stream.read( (char*)buffer, BLOCK_LEN); /* Flawfinder: ignore */ // note that return value of read is unusable. |
184 | len=stream.gcount(); | 187 | len=stream.gcount(); |
185 | update(buffer, len); | 188 | update(buffer, len); |
186 | } | 189 | } |
@@ -366,11 +369,48 @@ void LLMD5::init(){ | |||
366 | #define S43 15 | 369 | #define S43 15 |
367 | #define S44 21 | 370 | #define S44 21 |
368 | 371 | ||
372 | // #defines are faster then inline, etc because the compiler is not required to inline. | ||
373 | // Timing tests prove that this works ~40% faster on win with msvc++2k3 over using static inline. | ||
374 | |||
375 | /* F, G, H and I are basic MD5 functions. | ||
376 | */ | ||
377 | #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) | ||
378 | #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) | ||
379 | #define H(x, y, z) ((x) ^ (y) ^ (z)) | ||
380 | #define I(x, y, z) ((y) ^ ((x) | (~z))) | ||
381 | |||
382 | /* ROTATE_LEFT rotates x left n bits. | ||
383 | */ | ||
384 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) | ||
385 | |||
386 | /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. | ||
387 | Rotation is separate from addition to prevent recomputation. | ||
388 | */ | ||
389 | #define FF(a, b, c, d, x, s, ac) { \ | ||
390 | (a) += F ((b), (c), (d)) + (x) + (U32)(ac); \ | ||
391 | (a) = ROTATE_LEFT ((a), (s)); \ | ||
392 | (a) += (b); \ | ||
393 | } | ||
394 | #define GG(a, b, c, d, x, s, ac) { \ | ||
395 | (a) += G ((b), (c), (d)) + (x) + (U32)(ac); \ | ||
396 | (a) = ROTATE_LEFT ((a), (s)); \ | ||
397 | (a) += (b); \ | ||
398 | } | ||
399 | #define HH(a, b, c, d, x, s, ac) { \ | ||
400 | (a) += H ((b), (c), (d)) + (x) + (U32)(ac); \ | ||
401 | (a) = ROTATE_LEFT ((a), (s)); \ | ||
402 | (a) += (b); \ | ||
403 | } | ||
404 | #define II(a, b, c, d, x, s, ac) { \ | ||
405 | (a) += I ((b), (c), (d)) + (x) + (U32)(ac); \ | ||
406 | (a) = ROTATE_LEFT ((a), (s)); \ | ||
407 | (a) += (b); \ | ||
408 | } | ||
369 | 409 | ||
370 | 410 | ||
371 | 411 | ||
372 | // LLMD5 basic transformation. Transforms state based on block. | 412 | // LLMD5 basic transformation. Transforms state based on block. |
373 | void LLMD5::transform (const uint1 block[64]){ | 413 | void LLMD5::transform (const U8 block[64]){ |
374 | 414 | ||
375 | uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; | 415 | uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; |
376 | 416 | ||
@@ -489,64 +529,3 @@ void LLMD5::decode (uint4 *output, const uint1 *input, const uint4 len){ | |||
489 | output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) | | 529 | output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) | |
490 | (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24); | 530 | (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24); |
491 | } | 531 | } |
492 | |||
493 | |||
494 | |||
495 | |||
496 | |||
497 | // ROTATE_LEFT rotates x left n bits. | ||
498 | |||
499 | inline unsigned int LLMD5::rotate_left (uint4 x, uint4 n){ | ||
500 | return (x << n) | (x >> (32-n)) ; | ||
501 | } | ||
502 | |||
503 | |||
504 | |||
505 | |||
506 | // F, G, H and I are basic MD5 functions. | ||
507 | |||
508 | inline unsigned int LLMD5::F (uint4 x, uint4 y, uint4 z){ | ||
509 | return (x & y) | (~x & z); | ||
510 | } | ||
511 | |||
512 | inline unsigned int LLMD5::G (uint4 x, uint4 y, uint4 z){ | ||
513 | return (x & z) | (y & ~z); | ||
514 | } | ||
515 | |||
516 | inline unsigned int LLMD5::H (uint4 x, uint4 y, uint4 z){ | ||
517 | return x ^ y ^ z; | ||
518 | } | ||
519 | |||
520 | inline unsigned int LLMD5::I (uint4 x, uint4 y, uint4 z){ | ||
521 | return y ^ (x | ~z); | ||
522 | } | ||
523 | |||
524 | |||
525 | |||
526 | // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. | ||
527 | // Rotation is separate from addition to prevent recomputation. | ||
528 | |||
529 | |||
530 | inline void LLMD5::FF(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, | ||
531 | uint4 s, uint4 ac){ | ||
532 | a += F(b, c, d) + x + ac; | ||
533 | a = rotate_left (a, s) +b; | ||
534 | } | ||
535 | |||
536 | inline void LLMD5::GG(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, | ||
537 | uint4 s, uint4 ac){ | ||
538 | a += G(b, c, d) + x + ac; | ||
539 | a = rotate_left (a, s) +b; | ||
540 | } | ||
541 | |||
542 | inline void LLMD5::HH(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, | ||
543 | uint4 s, uint4 ac){ | ||
544 | a += H(b, c, d) + x + ac; | ||
545 | a = rotate_left (a, s) +b; | ||
546 | } | ||
547 | |||
548 | inline void LLMD5::II(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, | ||
549 | uint4 s, uint4 ac){ | ||
550 | a += I(b, c, d) + x + ac; | ||
551 | a = rotate_left (a, s) +b; | ||
552 | } | ||