aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-29 20:44:51 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-29 20:44:51 +0000
commitdb15cb72e2dad0e2dbed77665ac848a49b950038 (patch)
tree5fe543705a4e5be98bb07b90889595c582d6f3fd
parenta2949aa217f255341a0507b6e340285bdea1001f (diff)
downloadbusybox-w32-db15cb72e2dad0e2dbed77665ac848a49b950038.tar.gz
busybox-w32-db15cb72e2dad0e2dbed77665ac848a49b950038.tar.bz2
busybox-w32-db15cb72e2dad0e2dbed77665ac848a49b950038.zip
A really nice patch from Manuel Novoa III for compile time
configurable size/speed tradeoffs.
-rw-r--r--coreutils/md5sum.c186
-rw-r--r--md5sum.c186
2 files changed, 372 insertions, 0 deletions
diff --git a/coreutils/md5sum.c b/coreutils/md5sum.c
index dcb05c156..643f8271d 100644
--- a/coreutils/md5sum.c
+++ b/coreutils/md5sum.c
@@ -20,6 +20,24 @@
20/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu> */ 20/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu> */
21/* Hacked to work with BusyBox by Alfred M. Szmidt <ams@trillian.itslinux.org> */ 21/* Hacked to work with BusyBox by Alfred M. Szmidt <ams@trillian.itslinux.org> */
22 22
23/*
24 * June 29, 2001 Manuel Novoa III
25 *
26 * Added MD5SUM_SIZE_VS_SPEED configuration option.
27 *
28 * Current valid values, with data from my system for comparison, are:
29 * (using uClibc and running on linux-2.4.4.tar.bz2)
30 * user times (sec) text size (386)
31 * 0 (fastest) 1.1 6144
32 * 1 1.4 5392
33 * 2 3.0 5088
34 * 3 (smallest) 5.1 4912
35 */
36
37#define MD5SUM_SIZE_VS_SPEED 2
38
39/**********************************************************************/
40
23#include <stdio.h> 41#include <stdio.h>
24#include <errno.h> 42#include <errno.h>
25#include <ctype.h> 43#include <ctype.h>
@@ -184,9 +202,11 @@ extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
184 202
185 203
186 204
205#if MD5SUM_SIZE_VS_SPEED == 0
187/* This array contains the bytes used to pad the buffer to the next 206/* This array contains the bytes used to pad the buffer to the next
188 64-byte boundary. (RFC 1321, 3.1: Step 1) */ 207 64-byte boundary. (RFC 1321, 3.1: Step 1) */
189static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; 208static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
209#endif
190 210
191/* Initialize structure containing state of computation. 211/* Initialize structure containing state of computation.
192 (RFC 1321, 3.3: Step 3) */ 212 (RFC 1321, 3.3: Step 3) */
@@ -233,7 +253,12 @@ void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf)
233 ++ctx->total[1]; 253 ++ctx->total[1];
234 254
235 pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; 255 pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
256#if MD5SUM_SIZE_VS_SPEED > 0
257 memset(&ctx->buffer[bytes], 0, pad);
258 ctx->buffer[bytes] = 0x80;
259#else
236 memcpy(&ctx->buffer[bytes], fillbuf, pad); 260 memcpy(&ctx->buffer[bytes], fillbuf, pad);
261#endif
237 262
238 /* Put the 64-bit file length in *bits* at the end of the buffer. */ 263 /* Put the 64-bit file length in *bits* at the end of the buffer. */
239 *(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3); 264 *(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3);
@@ -369,6 +394,49 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
369 const md5_uint32 *words = buffer; 394 const md5_uint32 *words = buffer;
370 size_t nwords = len / sizeof(md5_uint32); 395 size_t nwords = len / sizeof(md5_uint32);
371 const md5_uint32 *endp = words + nwords; 396 const md5_uint32 *endp = words + nwords;
397#if MD5SUM_SIZE_VS_SPEED > 0
398 static const md5_uint32 C_array[] = {
399 /* round 1 */
400 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
401 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
402 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
403 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
404 /* round 2 */
405 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
406 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
407 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
408 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
409 /* round 3 */
410 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
411 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
412 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
413 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
414 /* round 4 */
415 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
416 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
417 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
418 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
419 };
420
421 static const char P_array[] = {
422#if MD5SUM_SIZE_VS_SPEED > 1
423 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
424#endif
425 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
426 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
427 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */
428 };
429
430#if MD5SUM_SIZE_VS_SPEED > 1
431 static const char S_array[] = {
432 7, 12, 17, 22,
433 5, 9, 14, 20,
434 4, 11, 16, 23,
435 6, 10, 15, 21
436 };
437#endif
438#endif
439
372 md5_uint32 A = ctx->A; 440 md5_uint32 A = ctx->A;
373 md5_uint32 B = ctx->B; 441 md5_uint32 B = ctx->B;
374 md5_uint32 C = ctx->C; 442 md5_uint32 C = ctx->C;
@@ -390,6 +458,79 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
390 md5_uint32 C_save = C; 458 md5_uint32 C_save = C;
391 md5_uint32 D_save = D; 459 md5_uint32 D_save = D;
392 460
461#if MD5SUM_SIZE_VS_SPEED > 1
462#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
463
464 const md5_uint32 *pc;
465 const char *pp;
466 const char *ps;
467 int i;
468 md5_uint32 temp;
469
470 for ( i=0 ; i < 16 ; i++ ) {
471 cwp[i] = SWAP(words[i]);
472 }
473 words += 16;
474
475#if MD5SUM_SIZE_VS_SPEED > 2
476 pc = C_array; pp = P_array; ps = S_array - 4;
477
478 for ( i = 0 ; i < 64 ; i++ ) {
479 if ((i&0x0f) == 0) ps += 4;
480 temp = A;
481 switch (i>>4) {
482 case 0:
483 temp += FF(B,C,D);
484 break;
485 case 1:
486 temp += FG(B,C,D);
487 break;
488 case 2:
489 temp += FH(B,C,D);
490 break;
491 case 3:
492 temp += FI(B,C,D);
493 break;
494 }
495 temp += cwp[(int)(*pp++)] + *pc++;
496 temp = CYCLIC (temp, ps[i&3]);
497 temp += B;
498 A = D; D = C; C = B; B = temp;
499 }
500#else
501 pc = C_array; pp = P_array; ps = S_array;
502
503 for ( i = 0 ; i < 16 ; i++ ) {
504 temp = A + FF(B,C,D) + cwp[(int)(*pp++)] + *pc++;
505 temp = CYCLIC (temp, ps[i&3]);
506 temp += B;
507 A = D; D = C; C = B; B = temp;
508 }
509
510 ps += 4;
511 for ( i = 0 ; i < 16 ; i++ ) {
512 temp = A + FG(B,C,D) + cwp[(int)(*pp++)] + *pc++;
513 temp = CYCLIC (temp, ps[i&3]);
514 temp += B;
515 A = D; D = C; C = B; B = temp;
516 }
517 ps += 4;
518 for ( i = 0 ; i < 16 ; i++ ) {
519 temp = A + FH(B,C,D) + cwp[(int)(*pp++)] + *pc++;
520 temp = CYCLIC (temp, ps[i&3]);
521 temp += B;
522 A = D; D = C; C = B; B = temp;
523 }
524 ps += 4;
525 for ( i = 0 ; i < 16 ; i++ ) {
526 temp = A + FI(B,C,D) + cwp[(int)(*pp++)] + *pc++;
527 temp = CYCLIC (temp, ps[i&3]);
528 temp += B;
529 A = D; D = C; C = B; B = temp;
530 }
531
532#endif
533#else
393 /* First round: using the given function, the context and a constant 534 /* First round: using the given function, the context and a constant
394 the next context is computed. Because the algorithms processing 535 the next context is computed. Because the algorithms processing
395 unit is a 32-bit word and it is determined to work on words in 536 unit is a 32-bit word and it is determined to work on words in
@@ -417,7 +558,22 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
417 T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 558 T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
418 */ 559 */
419 560
561#if MD5SUM_SIZE_VS_SPEED == 1
562 const md5_uint32 *pc;
563 const char *pp;
564 int i;
565#endif
566
420 /* Round 1. */ 567 /* Round 1. */
568#if MD5SUM_SIZE_VS_SPEED == 1
569 pc = C_array;
570 for ( i=0 ; i < 4 ; i++ ) {
571 OP(A, B, C, D, 7, *pc++);
572 OP(D, A, B, C, 12, *pc++);
573 OP(C, D, A, B, 17, *pc++);
574 OP(B, C, D, A, 22, *pc++);
575 }
576#else
421 OP(A, B, C, D, 7, 0xd76aa478); 577 OP(A, B, C, D, 7, 0xd76aa478);
422 OP(D, A, B, C, 12, 0xe8c7b756); 578 OP(D, A, B, C, 12, 0xe8c7b756);
423 OP(C, D, A, B, 17, 0x242070db); 579 OP(C, D, A, B, 17, 0x242070db);
@@ -434,6 +590,7 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
434 OP(D, A, B, C, 12, 0xfd987193); 590 OP(D, A, B, C, 12, 0xfd987193);
435 OP(C, D, A, B, 17, 0xa679438e); 591 OP(C, D, A, B, 17, 0xa679438e);
436 OP(B, C, D, A, 22, 0x49b40821); 592 OP(B, C, D, A, 22, 0x49b40821);
593#endif
437 594
438 /* For the second to fourth round we have the possibly swapped words 595 /* For the second to fourth round we have the possibly swapped words
439 in CORRECT_WORDS. Redefine the macro to take an additional first 596 in CORRECT_WORDS. Redefine the macro to take an additional first
@@ -449,6 +606,15 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
449 while (0) 606 while (0)
450 607
451 /* Round 2. */ 608 /* Round 2. */
609#if MD5SUM_SIZE_VS_SPEED == 1
610 pp = P_array;
611 for ( i=0 ; i < 4 ; i++ ) {
612 OP(FG, A, B, C, D, (int)(*pp++), 5, *pc++);
613 OP(FG, D, A, B, C, (int)(*pp++), 9, *pc++);
614 OP(FG, C, D, A, B, (int)(*pp++), 14, *pc++);
615 OP(FG, B, C, D, A, (int)(*pp++), 20, *pc++);
616 }
617#else
452 OP(FG, A, B, C, D, 1, 5, 0xf61e2562); 618 OP(FG, A, B, C, D, 1, 5, 0xf61e2562);
453 OP(FG, D, A, B, C, 6, 9, 0xc040b340); 619 OP(FG, D, A, B, C, 6, 9, 0xc040b340);
454 OP(FG, C, D, A, B, 11, 14, 0x265e5a51); 620 OP(FG, C, D, A, B, 11, 14, 0x265e5a51);
@@ -465,8 +631,17 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
465 OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8); 631 OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8);
466 OP(FG, C, D, A, B, 7, 14, 0x676f02d9); 632 OP(FG, C, D, A, B, 7, 14, 0x676f02d9);
467 OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a); 633 OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
634#endif
468 635
469 /* Round 3. */ 636 /* Round 3. */
637#if MD5SUM_SIZE_VS_SPEED == 1
638 for ( i=0 ; i < 4 ; i++ ) {
639 OP(FH, A, B, C, D, (int)(*pp++), 4, *pc++);
640 OP(FH, D, A, B, C, (int)(*pp++), 11, *pc++);
641 OP(FH, C, D, A, B, (int)(*pp++), 16, *pc++);
642 OP(FH, B, C, D, A, (int)(*pp++), 23, *pc++);
643 }
644#else
470 OP(FH, A, B, C, D, 5, 4, 0xfffa3942); 645 OP(FH, A, B, C, D, 5, 4, 0xfffa3942);
471 OP(FH, D, A, B, C, 8, 11, 0x8771f681); 646 OP(FH, D, A, B, C, 8, 11, 0x8771f681);
472 OP(FH, C, D, A, B, 11, 16, 0x6d9d6122); 647 OP(FH, C, D, A, B, 11, 16, 0x6d9d6122);
@@ -483,8 +658,17 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
483 OP(FH, D, A, B, C, 12, 11, 0xe6db99e5); 658 OP(FH, D, A, B, C, 12, 11, 0xe6db99e5);
484 OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8); 659 OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8);
485 OP(FH, B, C, D, A, 2, 23, 0xc4ac5665); 660 OP(FH, B, C, D, A, 2, 23, 0xc4ac5665);
661#endif
486 662
487 /* Round 4. */ 663 /* Round 4. */
664#if MD5SUM_SIZE_VS_SPEED == 1
665 for ( i=0 ; i < 4 ; i++ ) {
666 OP(FI, A, B, C, D, (int)(*pp++), 6, *pc++);
667 OP(FI, D, A, B, C, (int)(*pp++), 10, *pc++);
668 OP(FI, C, D, A, B, (int)(*pp++), 15, *pc++);
669 OP(FI, B, C, D, A, (int)(*pp++), 21, *pc++);
670 }
671#else
488 OP(FI, A, B, C, D, 0, 6, 0xf4292244); 672 OP(FI, A, B, C, D, 0, 6, 0xf4292244);
489 OP(FI, D, A, B, C, 7, 10, 0x432aff97); 673 OP(FI, D, A, B, C, 7, 10, 0x432aff97);
490 OP(FI, C, D, A, B, 14, 15, 0xab9423a7); 674 OP(FI, C, D, A, B, 14, 15, 0xab9423a7);
@@ -501,6 +685,8 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
501 OP(FI, D, A, B, C, 11, 10, 0xbd3af235); 685 OP(FI, D, A, B, C, 11, 10, 0xbd3af235);
502 OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb); 686 OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
503 OP(FI, B, C, D, A, 9, 21, 0xeb86d391); 687 OP(FI, B, C, D, A, 9, 21, 0xeb86d391);
688#endif
689#endif
504 690
505 /* Add the starting values of the context. */ 691 /* Add the starting values of the context. */
506 A += A_save; 692 A += A_save;
diff --git a/md5sum.c b/md5sum.c
index dcb05c156..643f8271d 100644
--- a/md5sum.c
+++ b/md5sum.c
@@ -20,6 +20,24 @@
20/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu> */ 20/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu> */
21/* Hacked to work with BusyBox by Alfred M. Szmidt <ams@trillian.itslinux.org> */ 21/* Hacked to work with BusyBox by Alfred M. Szmidt <ams@trillian.itslinux.org> */
22 22
23/*
24 * June 29, 2001 Manuel Novoa III
25 *
26 * Added MD5SUM_SIZE_VS_SPEED configuration option.
27 *
28 * Current valid values, with data from my system for comparison, are:
29 * (using uClibc and running on linux-2.4.4.tar.bz2)
30 * user times (sec) text size (386)
31 * 0 (fastest) 1.1 6144
32 * 1 1.4 5392
33 * 2 3.0 5088
34 * 3 (smallest) 5.1 4912
35 */
36
37#define MD5SUM_SIZE_VS_SPEED 2
38
39/**********************************************************************/
40
23#include <stdio.h> 41#include <stdio.h>
24#include <errno.h> 42#include <errno.h>
25#include <ctype.h> 43#include <ctype.h>
@@ -184,9 +202,11 @@ extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
184 202
185 203
186 204
205#if MD5SUM_SIZE_VS_SPEED == 0
187/* This array contains the bytes used to pad the buffer to the next 206/* This array contains the bytes used to pad the buffer to the next
188 64-byte boundary. (RFC 1321, 3.1: Step 1) */ 207 64-byte boundary. (RFC 1321, 3.1: Step 1) */
189static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; 208static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
209#endif
190 210
191/* Initialize structure containing state of computation. 211/* Initialize structure containing state of computation.
192 (RFC 1321, 3.3: Step 3) */ 212 (RFC 1321, 3.3: Step 3) */
@@ -233,7 +253,12 @@ void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf)
233 ++ctx->total[1]; 253 ++ctx->total[1];
234 254
235 pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; 255 pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
256#if MD5SUM_SIZE_VS_SPEED > 0
257 memset(&ctx->buffer[bytes], 0, pad);
258 ctx->buffer[bytes] = 0x80;
259#else
236 memcpy(&ctx->buffer[bytes], fillbuf, pad); 260 memcpy(&ctx->buffer[bytes], fillbuf, pad);
261#endif
237 262
238 /* Put the 64-bit file length in *bits* at the end of the buffer. */ 263 /* Put the 64-bit file length in *bits* at the end of the buffer. */
239 *(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3); 264 *(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3);
@@ -369,6 +394,49 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
369 const md5_uint32 *words = buffer; 394 const md5_uint32 *words = buffer;
370 size_t nwords = len / sizeof(md5_uint32); 395 size_t nwords = len / sizeof(md5_uint32);
371 const md5_uint32 *endp = words + nwords; 396 const md5_uint32 *endp = words + nwords;
397#if MD5SUM_SIZE_VS_SPEED > 0
398 static const md5_uint32 C_array[] = {
399 /* round 1 */
400 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
401 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
402 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
403 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
404 /* round 2 */
405 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
406 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
407 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
408 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
409 /* round 3 */
410 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
411 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
412 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
413 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
414 /* round 4 */
415 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
416 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
417 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
418 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
419 };
420
421 static const char P_array[] = {
422#if MD5SUM_SIZE_VS_SPEED > 1
423 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */
424#endif
425 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */
426 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */
427 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */
428 };
429
430#if MD5SUM_SIZE_VS_SPEED > 1
431 static const char S_array[] = {
432 7, 12, 17, 22,
433 5, 9, 14, 20,
434 4, 11, 16, 23,
435 6, 10, 15, 21
436 };
437#endif
438#endif
439
372 md5_uint32 A = ctx->A; 440 md5_uint32 A = ctx->A;
373 md5_uint32 B = ctx->B; 441 md5_uint32 B = ctx->B;
374 md5_uint32 C = ctx->C; 442 md5_uint32 C = ctx->C;
@@ -390,6 +458,79 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
390 md5_uint32 C_save = C; 458 md5_uint32 C_save = C;
391 md5_uint32 D_save = D; 459 md5_uint32 D_save = D;
392 460
461#if MD5SUM_SIZE_VS_SPEED > 1
462#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
463
464 const md5_uint32 *pc;
465 const char *pp;
466 const char *ps;
467 int i;
468 md5_uint32 temp;
469
470 for ( i=0 ; i < 16 ; i++ ) {
471 cwp[i] = SWAP(words[i]);
472 }
473 words += 16;
474
475#if MD5SUM_SIZE_VS_SPEED > 2
476 pc = C_array; pp = P_array; ps = S_array - 4;
477
478 for ( i = 0 ; i < 64 ; i++ ) {
479 if ((i&0x0f) == 0) ps += 4;
480 temp = A;
481 switch (i>>4) {
482 case 0:
483 temp += FF(B,C,D);
484 break;
485 case 1:
486 temp += FG(B,C,D);
487 break;
488 case 2:
489 temp += FH(B,C,D);
490 break;
491 case 3:
492 temp += FI(B,C,D);
493 break;
494 }
495 temp += cwp[(int)(*pp++)] + *pc++;
496 temp = CYCLIC (temp, ps[i&3]);
497 temp += B;
498 A = D; D = C; C = B; B = temp;
499 }
500#else
501 pc = C_array; pp = P_array; ps = S_array;
502
503 for ( i = 0 ; i < 16 ; i++ ) {
504 temp = A + FF(B,C,D) + cwp[(int)(*pp++)] + *pc++;
505 temp = CYCLIC (temp, ps[i&3]);
506 temp += B;
507 A = D; D = C; C = B; B = temp;
508 }
509
510 ps += 4;
511 for ( i = 0 ; i < 16 ; i++ ) {
512 temp = A + FG(B,C,D) + cwp[(int)(*pp++)] + *pc++;
513 temp = CYCLIC (temp, ps[i&3]);
514 temp += B;
515 A = D; D = C; C = B; B = temp;
516 }
517 ps += 4;
518 for ( i = 0 ; i < 16 ; i++ ) {
519 temp = A + FH(B,C,D) + cwp[(int)(*pp++)] + *pc++;
520 temp = CYCLIC (temp, ps[i&3]);
521 temp += B;
522 A = D; D = C; C = B; B = temp;
523 }
524 ps += 4;
525 for ( i = 0 ; i < 16 ; i++ ) {
526 temp = A + FI(B,C,D) + cwp[(int)(*pp++)] + *pc++;
527 temp = CYCLIC (temp, ps[i&3]);
528 temp += B;
529 A = D; D = C; C = B; B = temp;
530 }
531
532#endif
533#else
393 /* First round: using the given function, the context and a constant 534 /* First round: using the given function, the context and a constant
394 the next context is computed. Because the algorithms processing 535 the next context is computed. Because the algorithms processing
395 unit is a 32-bit word and it is determined to work on words in 536 unit is a 32-bit word and it is determined to work on words in
@@ -417,7 +558,22 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
417 T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 558 T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
418 */ 559 */
419 560
561#if MD5SUM_SIZE_VS_SPEED == 1
562 const md5_uint32 *pc;
563 const char *pp;
564 int i;
565#endif
566
420 /* Round 1. */ 567 /* Round 1. */
568#if MD5SUM_SIZE_VS_SPEED == 1
569 pc = C_array;
570 for ( i=0 ; i < 4 ; i++ ) {
571 OP(A, B, C, D, 7, *pc++);
572 OP(D, A, B, C, 12, *pc++);
573 OP(C, D, A, B, 17, *pc++);
574 OP(B, C, D, A, 22, *pc++);
575 }
576#else
421 OP(A, B, C, D, 7, 0xd76aa478); 577 OP(A, B, C, D, 7, 0xd76aa478);
422 OP(D, A, B, C, 12, 0xe8c7b756); 578 OP(D, A, B, C, 12, 0xe8c7b756);
423 OP(C, D, A, B, 17, 0x242070db); 579 OP(C, D, A, B, 17, 0x242070db);
@@ -434,6 +590,7 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
434 OP(D, A, B, C, 12, 0xfd987193); 590 OP(D, A, B, C, 12, 0xfd987193);
435 OP(C, D, A, B, 17, 0xa679438e); 591 OP(C, D, A, B, 17, 0xa679438e);
436 OP(B, C, D, A, 22, 0x49b40821); 592 OP(B, C, D, A, 22, 0x49b40821);
593#endif
437 594
438 /* For the second to fourth round we have the possibly swapped words 595 /* For the second to fourth round we have the possibly swapped words
439 in CORRECT_WORDS. Redefine the macro to take an additional first 596 in CORRECT_WORDS. Redefine the macro to take an additional first
@@ -449,6 +606,15 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
449 while (0) 606 while (0)
450 607
451 /* Round 2. */ 608 /* Round 2. */
609#if MD5SUM_SIZE_VS_SPEED == 1
610 pp = P_array;
611 for ( i=0 ; i < 4 ; i++ ) {
612 OP(FG, A, B, C, D, (int)(*pp++), 5, *pc++);
613 OP(FG, D, A, B, C, (int)(*pp++), 9, *pc++);
614 OP(FG, C, D, A, B, (int)(*pp++), 14, *pc++);
615 OP(FG, B, C, D, A, (int)(*pp++), 20, *pc++);
616 }
617#else
452 OP(FG, A, B, C, D, 1, 5, 0xf61e2562); 618 OP(FG, A, B, C, D, 1, 5, 0xf61e2562);
453 OP(FG, D, A, B, C, 6, 9, 0xc040b340); 619 OP(FG, D, A, B, C, 6, 9, 0xc040b340);
454 OP(FG, C, D, A, B, 11, 14, 0x265e5a51); 620 OP(FG, C, D, A, B, 11, 14, 0x265e5a51);
@@ -465,8 +631,17 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
465 OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8); 631 OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8);
466 OP(FG, C, D, A, B, 7, 14, 0x676f02d9); 632 OP(FG, C, D, A, B, 7, 14, 0x676f02d9);
467 OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a); 633 OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
634#endif
468 635
469 /* Round 3. */ 636 /* Round 3. */
637#if MD5SUM_SIZE_VS_SPEED == 1
638 for ( i=0 ; i < 4 ; i++ ) {
639 OP(FH, A, B, C, D, (int)(*pp++), 4, *pc++);
640 OP(FH, D, A, B, C, (int)(*pp++), 11, *pc++);
641 OP(FH, C, D, A, B, (int)(*pp++), 16, *pc++);
642 OP(FH, B, C, D, A, (int)(*pp++), 23, *pc++);
643 }
644#else
470 OP(FH, A, B, C, D, 5, 4, 0xfffa3942); 645 OP(FH, A, B, C, D, 5, 4, 0xfffa3942);
471 OP(FH, D, A, B, C, 8, 11, 0x8771f681); 646 OP(FH, D, A, B, C, 8, 11, 0x8771f681);
472 OP(FH, C, D, A, B, 11, 16, 0x6d9d6122); 647 OP(FH, C, D, A, B, 11, 16, 0x6d9d6122);
@@ -483,8 +658,17 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
483 OP(FH, D, A, B, C, 12, 11, 0xe6db99e5); 658 OP(FH, D, A, B, C, 12, 11, 0xe6db99e5);
484 OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8); 659 OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8);
485 OP(FH, B, C, D, A, 2, 23, 0xc4ac5665); 660 OP(FH, B, C, D, A, 2, 23, 0xc4ac5665);
661#endif
486 662
487 /* Round 4. */ 663 /* Round 4. */
664#if MD5SUM_SIZE_VS_SPEED == 1
665 for ( i=0 ; i < 4 ; i++ ) {
666 OP(FI, A, B, C, D, (int)(*pp++), 6, *pc++);
667 OP(FI, D, A, B, C, (int)(*pp++), 10, *pc++);
668 OP(FI, C, D, A, B, (int)(*pp++), 15, *pc++);
669 OP(FI, B, C, D, A, (int)(*pp++), 21, *pc++);
670 }
671#else
488 OP(FI, A, B, C, D, 0, 6, 0xf4292244); 672 OP(FI, A, B, C, D, 0, 6, 0xf4292244);
489 OP(FI, D, A, B, C, 7, 10, 0x432aff97); 673 OP(FI, D, A, B, C, 7, 10, 0x432aff97);
490 OP(FI, C, D, A, B, 14, 15, 0xab9423a7); 674 OP(FI, C, D, A, B, 14, 15, 0xab9423a7);
@@ -501,6 +685,8 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
501 OP(FI, D, A, B, C, 11, 10, 0xbd3af235); 685 OP(FI, D, A, B, C, 11, 10, 0xbd3af235);
502 OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb); 686 OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
503 OP(FI, B, C, D, A, 9, 21, 0xeb86d391); 687 OP(FI, B, C, D, A, 9, 21, 0xeb86d391);
688#endif
689#endif
504 690
505 /* Add the starting values of the context. */ 691 /* Add the starting values of the context. */
506 A += A_save; 692 A += A_save;