Quellcode durchsuchen

[crypto] Eliminate repetitions in MD5 round constant table

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown vor 6 Jahren
Ursprung
Commit
32d54691e9
1 geänderte Dateien mit 10 neuen und 7 gelöschten Zeilen
  1. 10
    7
      src/crypto/md5.c

+ 10
- 7
src/crypto/md5.c Datei anzeigen

66
 };
66
 };
67
 
67
 
68
 /** MD5 shift amounts */
68
 /** MD5 shift amounts */
69
-static const uint8_t r[64] = {
70
-	7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
71
-	5,  9, 14, 20, 5,  9, 14, 20, 5,  9, 14, 20, 5,  9, 14, 20,
72
-	4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
73
-	6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
69
+static const uint8_t r[4][4] = {
70
+	{  7, 12, 17, 22 },
71
+	{  5,  9, 14, 20 },
72
+	{  4, 11, 16, 23 },
73
+	{  6, 10, 15, 21 },
74
 };
74
 };
75
 
75
 
76
 /**
76
 /**
174
 	uint32_t g;
174
 	uint32_t g;
175
 	uint32_t temp;
175
 	uint32_t temp;
176
 	struct md5_step *step;
176
 	struct md5_step *step;
177
+	unsigned int round;
177
 	unsigned int i;
178
 	unsigned int i;
178
 
179
 
179
 	/* Sanity checks */
180
 	/* Sanity checks */
201
 
202
 
202
 	/* Main loop */
203
 	/* Main loop */
203
 	for ( i = 0 ; i < 64 ; i++ ) {
204
 	for ( i = 0 ; i < 64 ; i++ ) {
204
-		step = &md5_steps[ i / 16 ];
205
+		round = ( i / 16 );
206
+		step = &md5_steps[round];
205
 		f = step->f ( &u.v );
207
 		f = step->f ( &u.v );
206
 		g = ( ( ( step->coefficient * i ) + step->constant ) % 16 );
208
 		g = ( ( ( step->coefficient * i ) + step->constant ) % 16 );
207
 		temp = *d;
209
 		temp = *d;
208
 		*d = *c;
210
 		*d = *c;
209
 		*c = *b;
211
 		*c = *b;
210
-		*b = ( *b + rol32 ( ( *a + f + k[i] + w[g] ), r[i] ) );
212
+		*b = ( *b + rol32 ( ( *a + f + k[i] + w[g] ),
213
+				    r[round][ i % 4 ] ) );
211
 		*a = temp;
214
 		*a = temp;
212
 		DBGC2 ( context, "%2d : %08x %08x %08x %08x\n",
215
 		DBGC2 ( context, "%2d : %08x %08x %08x %08x\n",
213
 			i, *a, *b, *c, *d );
216
 			i, *a, *b, *c, *d );

Laden…
Abbrechen
Speichern