diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-17 11:38:44 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-17 11:38:44 +0200 |
| commit | cfe114c4f3d4e1dfc00196d8df316874eaf2d2b8 (patch) | |
| tree | ab84548e02a82c6110383277ee29b5b6ace743fe | |
| parent | f6dacc23ff495cbdd3f1baf5985ded21a7e4a9c9 (diff) | |
| download | busybox-w32-cfe114c4f3d4e1dfc00196d8df316874eaf2d2b8.tar.gz busybox-w32-cfe114c4f3d4e1dfc00196d8df316874eaf2d2b8.tar.bz2 busybox-w32-cfe114c4f3d4e1dfc00196d8df316874eaf2d2b8.zip | |
md5: code shrink -5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | libbb/md5.c | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/libbb/md5.c b/libbb/md5.c index f5d083e3f..6001a9c8e 100644 --- a/libbb/md5.c +++ b/libbb/md5.c | |||
| @@ -64,7 +64,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 64 | 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, | 64 | 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, |
| 65 | /* round 2 */ | 65 | /* round 2 */ |
| 66 | 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, | 66 | 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, |
| 67 | 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, | 67 | 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, |
| 68 | 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, | 68 | 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, |
| 69 | 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, | 69 | 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, |
| 70 | /* round 3 */ | 70 | /* round 3 */ |
| @@ -86,28 +86,21 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 86 | 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */ | 86 | 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, /* 3 */ |
| 87 | 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */ | 87 | 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */ |
| 88 | }; | 88 | }; |
| 89 | # if MD5_SIZE_VS_SPEED > 1 | ||
| 90 | static const char S_array[] ALIGN1 = { | ||
| 91 | 7, 12, 17, 22, | ||
| 92 | 5, 9, 14, 20, | ||
| 93 | 4, 11, 16, 23, | ||
| 94 | 6, 10, 15, 21 | ||
| 95 | }; | ||
| 96 | # endif | ||
| 97 | #endif | 89 | #endif |
| 98 | const uint32_t *words = (const void*) ctx->wbuffer; | 90 | const uint32_t *words = (const void*) ctx->wbuffer; |
| 99 | |||
| 100 | uint32_t A = ctx->A; | 91 | uint32_t A = ctx->A; |
| 101 | uint32_t B = ctx->B; | 92 | uint32_t B = ctx->B; |
| 102 | uint32_t C = ctx->C; | 93 | uint32_t C = ctx->C; |
| 103 | uint32_t D = ctx->D; | 94 | uint32_t D = ctx->D; |
| 104 | 95 | ||
| 105 | uint32_t A_save = A; | 96 | #if MD5_SIZE_VS_SPEED >= 2 /* 2 or 3 */ |
| 106 | uint32_t B_save = B; | ||
| 107 | uint32_t C_save = C; | ||
| 108 | uint32_t D_save = D; | ||
| 109 | 97 | ||
| 110 | #if MD5_SIZE_VS_SPEED > 1 | 98 | static const char S_array[] ALIGN1 = { |
| 99 | 7, 12, 17, 22, | ||
| 100 | 5, 9, 14, 20, | ||
| 101 | 4, 11, 16, 23, | ||
| 102 | 6, 10, 15, 21 | ||
| 103 | }; | ||
| 111 | const uint32_t *pc; | 104 | const uint32_t *pc; |
| 112 | const char *pp; | 105 | const char *pp; |
| 113 | const char *ps; | 106 | const char *ps; |
| @@ -119,7 +112,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 119 | words[i] = SWAP_LE32(words[i]); | 112 | words[i] = SWAP_LE32(words[i]); |
| 120 | # endif | 113 | # endif |
| 121 | 114 | ||
| 122 | # if MD5_SIZE_VS_SPEED > 2 | 115 | # if MD5_SIZE_VS_SPEED == 3 |
| 123 | pc = C_array; | 116 | pc = C_array; |
| 124 | pp = P_array; | 117 | pp = P_array; |
| 125 | ps = S_array - 4; | 118 | ps = S_array - 4; |
| @@ -149,7 +142,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 149 | C = B; | 142 | C = B; |
| 150 | B = temp; | 143 | B = temp; |
| 151 | } | 144 | } |
| 152 | # else /* MD5_SIZE_VS_SPEED == 2 */ | 145 | # else /* MD5_SIZE_VS_SPEED == 2 */ |
| 153 | pc = C_array; | 146 | pc = C_array; |
| 154 | pp = P_array; | 147 | pp = P_array; |
| 155 | ps = S_array; | 148 | ps = S_array; |
| @@ -194,8 +187,23 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 194 | B = temp; | 187 | B = temp; |
| 195 | } | 188 | } |
| 196 | # endif | 189 | # endif |
| 190 | /* Add checksum to the starting values */ | ||
| 191 | ctx->A += A; | ||
| 192 | ctx->B += B; | ||
| 193 | ctx->C += C; | ||
| 194 | ctx->D += D; | ||
| 197 | 195 | ||
| 198 | #else /* MD5_SIZE_VS_SPEED == 0 or 1 */ | 196 | #else /* MD5_SIZE_VS_SPEED == 0 or 1 */ |
| 197 | |||
| 198 | uint32_t A_save = A; | ||
| 199 | uint32_t B_save = B; | ||
| 200 | uint32_t C_save = C; | ||
| 201 | uint32_t D_save = D; | ||
| 202 | # if MD5_SIZE_VS_SPEED == 1 | ||
| 203 | const uint32_t *pc; | ||
| 204 | const char *pp; | ||
| 205 | int i; | ||
| 206 | # endif | ||
| 199 | 207 | ||
| 200 | /* First round: using the given function, the context and a constant | 208 | /* First round: using the given function, the context and a constant |
| 201 | the next context is computed. Because the algorithm's processing | 209 | the next context is computed. Because the algorithm's processing |
| @@ -212,13 +220,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 212 | a += b; \ | 220 | a += b; \ |
| 213 | } while (0) | 221 | } while (0) |
| 214 | 222 | ||
| 215 | # if MD5_SIZE_VS_SPEED == 1 | 223 | /* Round 1 */ |
| 216 | const uint32_t *pc; | ||
| 217 | const char *pp; | ||
| 218 | int i; | ||
| 219 | # endif | ||
| 220 | |||
| 221 | /* Round 1. */ | ||
| 222 | # if MD5_SIZE_VS_SPEED == 1 | 224 | # if MD5_SIZE_VS_SPEED == 1 |
| 223 | pc = C_array; | 225 | pc = C_array; |
| 224 | for (i = 0; i < 4; i++) { | 226 | for (i = 0; i < 4; i++) { |
| @@ -258,7 +260,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 258 | a += b; \ | 260 | a += b; \ |
| 259 | } while (0) | 261 | } while (0) |
| 260 | 262 | ||
| 261 | /* Round 2. */ | 263 | /* Round 2 */ |
| 262 | # if MD5_SIZE_VS_SPEED == 1 | 264 | # if MD5_SIZE_VS_SPEED == 1 |
| 263 | pp = P_array; | 265 | pp = P_array; |
| 264 | for (i = 0; i < 4; i++) { | 266 | for (i = 0; i < 4; i++) { |
| @@ -286,7 +288,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 286 | OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a); | 288 | OP(FG, B, C, D, A, 12, 20, 0x8d2a4c8a); |
| 287 | # endif | 289 | # endif |
| 288 | 290 | ||
| 289 | /* Round 3. */ | 291 | /* Round 3 */ |
| 290 | # if MD5_SIZE_VS_SPEED == 1 | 292 | # if MD5_SIZE_VS_SPEED == 1 |
| 291 | for (i = 0; i < 4; i++) { | 293 | for (i = 0; i < 4; i++) { |
| 292 | OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++); | 294 | OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++); |
| @@ -313,7 +315,7 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 313 | OP(FH, B, C, D, A, 2, 23, 0xc4ac5665); | 315 | OP(FH, B, C, D, A, 2, 23, 0xc4ac5665); |
| 314 | # endif | 316 | # endif |
| 315 | 317 | ||
| 316 | /* Round 4. */ | 318 | /* Round 4 */ |
| 317 | # if MD5_SIZE_VS_SPEED == 1 | 319 | # if MD5_SIZE_VS_SPEED == 1 |
| 318 | for (i = 0; i < 4; i++) { | 320 | for (i = 0; i < 4; i++) { |
| 319 | OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++); | 321 | OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++); |
| @@ -339,19 +341,12 @@ static void md5_process_block64(md5_ctx_t *ctx) | |||
| 339 | OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb); | 341 | OP(FI, C, D, A, B, 2, 15, 0x2ad7d2bb); |
| 340 | OP(FI, B, C, D, A, 9, 21, 0xeb86d391); | 342 | OP(FI, B, C, D, A, 9, 21, 0xeb86d391); |
| 341 | # endif | 343 | # endif |
| 344 | /* Add checksum to the starting values */ | ||
| 345 | ctx->A = A_save + A; | ||
| 346 | ctx->B = B_save + B; | ||
| 347 | ctx->C = C_save + C; | ||
| 348 | ctx->D = D_save + D; | ||
| 342 | #endif | 349 | #endif |
| 343 | |||
| 344 | /* Add the starting values of the context. */ | ||
| 345 | A += A_save; | ||
| 346 | B += B_save; | ||
| 347 | C += C_save; | ||
| 348 | D += D_save; | ||
| 349 | |||
| 350 | /* Put checksum in context given as argument. */ | ||
| 351 | ctx->A = A; | ||
| 352 | ctx->B = B; | ||
| 353 | ctx->C = C; | ||
| 354 | ctx->D = D; | ||
| 355 | } | 350 | } |
| 356 | 351 | ||
| 357 | /* Feed data through a temporary buffer to call md5_hash_aligned_block() | 352 | /* Feed data through a temporary buffer to call md5_hash_aligned_block() |
