[crypto] Eliminate repetitions in MD5 round constant table

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2017-11-12 18:30:08 +00:00
parent fb6b66ce13
commit 32d54691e9

View File

@@ -66,11 +66,11 @@ static const uint32_t k[64] = {
}; };
/** MD5 shift amounts */ /** MD5 shift amounts */
static const uint8_t r[64] = { static const uint8_t r[4][4] = {
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, { 7, 12, 17, 22 },
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, { 5, 9, 14, 20 },
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, { 4, 11, 16, 23 },
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 { 6, 10, 15, 21 },
}; };
/** /**
@@ -174,6 +174,7 @@ static void md5_digest ( struct md5_context *context ) {
uint32_t g; uint32_t g;
uint32_t temp; uint32_t temp;
struct md5_step *step; struct md5_step *step;
unsigned int round;
unsigned int i; unsigned int i;
/* Sanity checks */ /* Sanity checks */
@@ -201,13 +202,15 @@ static void md5_digest ( struct md5_context *context ) {
/* Main loop */ /* Main loop */
for ( i = 0 ; i < 64 ; i++ ) { for ( i = 0 ; i < 64 ; i++ ) {
step = &md5_steps[ i / 16 ]; round = ( i / 16 );
step = &md5_steps[round];
f = step->f ( &u.v ); f = step->f ( &u.v );
g = ( ( ( step->coefficient * i ) + step->constant ) % 16 ); g = ( ( ( step->coefficient * i ) + step->constant ) % 16 );
temp = *d; temp = *d;
*d = *c; *d = *c;
*c = *b; *c = *b;
*b = ( *b + rol32 ( ( *a + f + k[i] + w[g] ), r[i] ) ); *b = ( *b + rol32 ( ( *a + f + k[i] + w[g] ),
r[round][ i % 4 ] ) );
*a = temp; *a = temp;
DBGC2 ( context, "%2d : %08x %08x %08x %08x\n", DBGC2 ( context, "%2d : %08x %08x %08x %08x\n",
i, *a, *b, *c, *d ); i, *a, *b, *c, *d );