aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-15 18:05:51 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-15 18:05:51 +0200
commit3d160984944a915cfac13da2b835fa29fc556321 (patch)
tree69c0bff02e229b4e79da0f063fd85fa0d2c66002
parentc15613c9757f5a26da3623c1bcfa3580c81b74c3 (diff)
downloadbusybox-w32-3d160984944a915cfac13da2b835fa29fc556321.tar.gz
busybox-w32-3d160984944a915cfac13da2b835fa29fc556321.tar.bz2
busybox-w32-3d160984944a915cfac13da2b835fa29fc556321.zip
libbb/md5: small code shrink
function old new delta md5_end 151 123 -28 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--libbb/md5.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/libbb/md5.c b/libbb/md5.c
index d8655ba91..9e5b496ce 100644
--- a/libbb/md5.c
+++ b/libbb/md5.c
@@ -56,6 +56,10 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
56 const uint32_t *words = buffer; 56 const uint32_t *words = buffer;
57 57
58#if MD5_SIZE_VS_SPEED > 0 58#if MD5_SIZE_VS_SPEED > 0
59 /* Before we start, one word to the strange constants.
60 They are defined in RFC 1321 as
61 T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64
62 */
59 static const uint32_t C_array[] = { 63 static const uint32_t C_array[] = {
60 /* round 1 */ 64 /* round 1 */
61 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 65 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
@@ -93,15 +97,13 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
93 4, 11, 16, 23, 97 4, 11, 16, 23,
94 6, 10, 15, 21 98 6, 10, 15, 21
95 }; 99 };
96# endif /* MD5_SIZE_VS_SPEED > 1 */ 100# endif
97#endif 101#endif
98 uint32_t A = ctx->A; 102 uint32_t A = ctx->A;
99 uint32_t B = ctx->B; 103 uint32_t B = ctx->B;
100 uint32_t C = ctx->C; 104 uint32_t C = ctx->C;
101 uint32_t D = ctx->D; 105 uint32_t D = ctx->D;
102 106
103 /* Process all bytes in the buffer with 64 bytes in each round of
104 the loop. */
105 uint32_t *cwp = correct_words; 107 uint32_t *cwp = correct_words;
106 uint32_t A_save = A; 108 uint32_t A_save = A;
107 uint32_t B_save = B; 109 uint32_t B_save = B;
@@ -149,7 +151,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
149 C = B; 151 C = B;
150 B = temp; 152 B = temp;
151 } 153 }
152# else 154# else /* MD5_SIZE_VS_SPEED == 2 */
153 pc = C_array; 155 pc = C_array;
154 pp = P_array; 156 pp = P_array;
155 ps = S_array; 157 ps = S_array;
@@ -193,15 +195,17 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
193 C = B; 195 C = B;
194 B = temp; 196 B = temp;
195 } 197 }
198# endif
199
200#else /* MD5_SIZE_VS_SPEED == 0 or 1 */
196 201
197# endif /* MD5_SIZE_VS_SPEED > 2 */
198#else
199 /* First round: using the given function, the context and a constant 202 /* First round: using the given function, the context and a constant
200 the next context is computed. Because the algorithms processing 203 the next context is computed. Because the algorithm's processing
201 unit is a 32-bit word and it is determined to work on words in 204 unit is a 32-bit word and it is determined to work on words in
202 little endian byte order we perhaps have to change the byte order 205 little endian byte order we perhaps have to change the byte order
203 before the computation. To reduce the work for the next steps 206 before the computation. To reduce the work for the next steps
204 we store the swapped words in the array CORRECT_WORDS. */ 207 we store the swapped words in the array CORRECT_WORDS. */
208# undef OP
205# define OP(a, b, c, d, s, T) \ 209# define OP(a, b, c, d, s, T) \
206 do { \ 210 do { \
207 a += FF(b, c, d) + (*cwp++ = SWAP_LE32(*words)) + T; \ 211 a += FF(b, c, d) + (*cwp++ = SWAP_LE32(*words)) + T; \
@@ -210,16 +214,11 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
210 a += b; \ 214 a += b; \
211 } while (0) 215 } while (0)
212 216
213 /* Before we start, one word to the strange constants.
214 They are defined in RFC 1321 as
215 T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64
216 */
217
218# if MD5_SIZE_VS_SPEED == 1 217# if MD5_SIZE_VS_SPEED == 1
219 const uint32_t *pc; 218 const uint32_t *pc;
220 const char *pp; 219 const char *pp;
221 int i; 220 int i;
222# endif /* MD5_SIZE_VS_SPEED */ 221# endif
223 222
224 /* Round 1. */ 223 /* Round 1. */
225# if MD5_SIZE_VS_SPEED == 1 224# if MD5_SIZE_VS_SPEED == 1
@@ -247,7 +246,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
247 OP(D, A, B, C, 12, 0xfd987193); 246 OP(D, A, B, C, 12, 0xfd987193);
248 OP(C, D, A, B, 17, 0xa679438e); 247 OP(C, D, A, B, 17, 0xa679438e);
249 OP(B, C, D, A, 22, 0x49b40821); 248 OP(B, C, D, A, 22, 0x49b40821);
250# endif /* MD5_SIZE_VS_SPEED == 1 */ 249# endif
251 250
252 /* For the second to fourth round we have the possibly swapped words 251 /* For the second to fourth round we have the possibly swapped words
253 in CORRECT_WORDS. Redefine the macro to take an additional first 252 in CORRECT_WORDS. Redefine the macro to take an additional first
@@ -286,7 +285,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
286 OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8); 285 OP(FG, D, A, B, C, 2, 9, 0xfcefa3f8);
287 OP(FG, C, D, A, B, 7, 14, 0x676f02d9); 286 OP(FG, C, D, A, B, 7, 14, 0x676f02d9);
288 OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a); 287 OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
289# endif /* MD5_SIZE_VS_SPEED == 1 */ 288# endif
290 289
291 /* Round 3. */ 290 /* Round 3. */
292# if MD5_SIZE_VS_SPEED == 1 291# if MD5_SIZE_VS_SPEED == 1
@@ -313,7 +312,7 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
313 OP(FH, D, A, B, C, 12, 11, 0xe6db99e5); 312 OP(FH, D, A, B, C, 12, 11, 0xe6db99e5);
314 OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8); 313 OP(FH, C, D, A, B, 15, 16, 0x1fa27cf8);
315 OP(FH, B, C, D, A, 2, 23, 0xc4ac5665); 314 OP(FH, B, C, D, A, 2, 23, 0xc4ac5665);
316# endif /* MD5_SIZE_VS_SPEED == 1 */ 315# endif
317 316
318 /* Round 4. */ 317 /* Round 4. */
319# if MD5_SIZE_VS_SPEED == 1 318# if MD5_SIZE_VS_SPEED == 1
@@ -340,8 +339,8 @@ static void md5_hash_block(const void *buffer, md5_ctx_t *ctx)
340 OP(FI, D, A, B, C, 11, 10, 0xbd3af235); 339 OP(FI, D, A, B, C, 11, 10, 0xbd3af235);
341 OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb); 340 OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
342 OP(FI, B, C, D, A, 9, 21, 0xeb86d391); 341 OP(FI, B, C, D, A, 9, 21, 0xeb86d391);
343# endif /* MD5_SIZE_VS_SPEED == 1 */ 342# endif
344#endif /* MD5_SIZE_VS_SPEED > 1 */ 343#endif
345 344
346 /* Add the starting values of the context. */ 345 /* Add the starting values of the context. */
347 A += A_save; 346 A += A_save;
@@ -395,6 +394,7 @@ void FAST_FUNC md5_hash(const void *buffer, size_t len, md5_ctx_t *ctx)
395 */ 394 */
396void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx) 395void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx)
397{ 396{
397 uint64_t total;
398 char *buf = ctx->buffer; 398 char *buf = ctx->buffer;
399 int i; 399 int i;
400 400
@@ -402,12 +402,16 @@ void FAST_FUNC md5_end(void *resbuf, md5_ctx_t *ctx)
402 buf[ctx->buflen++] = 0x80; 402 buf[ctx->buflen++] = 0x80;
403 memset(buf + ctx->buflen, 0, 128 - ctx->buflen); 403 memset(buf + ctx->buflen, 0, 128 - ctx->buflen);
404 404
405 /* Put the 64-bit file length in *bits* at the end of the buffer. */ 405 /* Put the 64-bit file length, expressed in *bits*,
406 ctx->total <<= 3; 406 * at the end of the buffer.
407 */
408 total = ctx->total << 3;
407 if (ctx->buflen > 56) 409 if (ctx->buflen > 56)
408 buf += 64; 410 buf += 64;
409 for (i = 0; i < 8; i++) 411 for (i = 0; i < 8; i++) {
410 buf[56 + i] = ctx->total >> (i*8); 412 buf[56 + i] = total;
413 total >>= 8;
414 }
411 415
412 /* Process last bytes. */ 416 /* Process last bytes. */
413 if (buf != ctx->buffer) 417 if (buf != ctx->buffer)