summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMichael Brown2017-11-12 19:30:08 +0100
committerMichael Brown2017-11-12 19:52:03 +0100
commit32d54691e97258b6fa3eb79a0ba11a400d89c331 (patch)
tree1ce2a54e07e497549a84585541ce4fda738e5d10 /src/crypto
parent[crypto] Fix endianness typo in comment (diff)
downloadipxe-32d54691e97258b6fa3eb79a0ba11a400d89c331.tar.gz
ipxe-32d54691e97258b6fa3eb79a0ba11a400d89c331.tar.xz
ipxe-32d54691e97258b6fa3eb79a0ba11a400d89c331.zip
[crypto] Eliminate repetitions in MD5 round constant table
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/md5.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/crypto/md5.c b/src/crypto/md5.c
index 493591f3..185a61f3 100644
--- a/src/crypto/md5.c
+++ b/src/crypto/md5.c
@@ -66,11 +66,11 @@ static const uint32_t k[64] = {
};
/** MD5 shift amounts */
-static const uint8_t r[64] = {
- 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,
- 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
+static const uint8_t r[4][4] = {
+ { 7, 12, 17, 22 },
+ { 5, 9, 14, 20 },
+ { 4, 11, 16, 23 },
+ { 6, 10, 15, 21 },
};
/**
@@ -174,6 +174,7 @@ static void md5_digest ( struct md5_context *context ) {
uint32_t g;
uint32_t temp;
struct md5_step *step;
+ unsigned int round;
unsigned int i;
/* Sanity checks */
@@ -201,13 +202,15 @@ static void md5_digest ( struct md5_context *context ) {
/* Main loop */
for ( i = 0 ; i < 64 ; i++ ) {
- step = &md5_steps[ i / 16 ];
+ round = ( i / 16 );
+ step = &md5_steps[round];
f = step->f ( &u.v );
g = ( ( ( step->coefficient * i ) + step->constant ) % 16 );
temp = *d;
*d = *c;
*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;
DBGC2 ( context, "%2d : %08x %08x %08x %08x\n",
i, *a, *b, *c, *d );