diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-10 13:25:57 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-10 13:25:57 +0200 |
commit | 522041ee7b10ac544b90c6a8d1d4fbf8a5d39c6d (patch) | |
tree | 412854af83f841f564faf842ca6cefc12a016236 /libbb | |
parent | 202a1b9284fd763e81340050d228103aef999675 (diff) | |
download | busybox-w32-522041ee7b10ac544b90c6a8d1d4fbf8a5d39c6d.tar.gz busybox-w32-522041ee7b10ac544b90c6a8d1d4fbf8a5d39c6d.tar.bz2 busybox-w32-522041ee7b10ac544b90c6a8d1d4fbf8a5d39c6d.zip |
regularize options which control size/speed trade
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Config.src | 4 | ||||
-rw-r--r-- | libbb/hash_md5_sha.c | 32 | ||||
-rw-r--r-- | libbb/hash_md5prime.c | 26 |
3 files changed, 31 insertions, 31 deletions
diff --git a/libbb/Config.src b/libbb/Config.src index f6f88b9ce..f45e43b04 100644 --- a/libbb/Config.src +++ b/libbb/Config.src | |||
@@ -14,9 +14,9 @@ config PASSWORD_MINLEN | |||
14 | help | 14 | help |
15 | Minimum allowable password length. | 15 | Minimum allowable password length. |
16 | 16 | ||
17 | config MD5_SIZE_VS_SPEED | 17 | config MD5_SMALL |
18 | int "MD5: Trade bytes for speed (0:fast, 3:slow)" | 18 | int "MD5: Trade bytes for speed (0:fast, 3:slow)" |
19 | default 2 | 19 | default 1 |
20 | range 0 3 | 20 | range 0 3 |
21 | help | 21 | help |
22 | Trade binary size versus speed for the md5sum algorithm. | 22 | Trade binary size versus speed for the md5sum algorithm. |
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index b87d1dde8..a313c2a65 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c | |||
@@ -104,12 +104,12 @@ static void FAST_FUNC common64_end(md5_ctx_t *ctx, int swap_needed) | |||
104 | */ | 104 | */ |
105 | 105 | ||
106 | /* 0: fastest, 3: smallest */ | 106 | /* 0: fastest, 3: smallest */ |
107 | #if CONFIG_MD5_SIZE_VS_SPEED < 0 | 107 | #if CONFIG_MD5_SMALL < 0 |
108 | # define MD5_SIZE_VS_SPEED 0 | 108 | # define MD5_SMALL 0 |
109 | #elif CONFIG_MD5_SIZE_VS_SPEED > 3 | 109 | #elif CONFIG_MD5_SMALL > 3 |
110 | # define MD5_SIZE_VS_SPEED 3 | 110 | # define MD5_SMALL 3 |
111 | #else | 111 | #else |
112 | # define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED | 112 | # define MD5_SMALL CONFIG_MD5_SMALL |
113 | #endif | 113 | #endif |
114 | 114 | ||
115 | /* These are the four functions used in the four steps of the MD5 algorithm | 115 | /* These are the four functions used in the four steps of the MD5 algorithm |
@@ -129,7 +129,7 @@ static void FAST_FUNC common64_end(md5_ctx_t *ctx, int swap_needed) | |||
129 | /* Hash a single block, 64 bytes long and 4-byte aligned */ | 129 | /* Hash a single block, 64 bytes long and 4-byte aligned */ |
130 | static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | 130 | static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) |
131 | { | 131 | { |
132 | #if MD5_SIZE_VS_SPEED > 0 | 132 | #if MD5_SMALL > 0 |
133 | /* Before we start, one word to the strange constants. | 133 | /* Before we start, one word to the strange constants. |
134 | They are defined in RFC 1321 as | 134 | They are defined in RFC 1321 as |
135 | T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64 | 135 | T[i] = (int)(4294967296.0 * fabs(sin(i))), i=1..64 |
@@ -157,7 +157,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
157 | 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 | 157 | 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 |
158 | }; | 158 | }; |
159 | static const char P_array[] ALIGN1 = { | 159 | static const char P_array[] ALIGN1 = { |
160 | # if MD5_SIZE_VS_SPEED > 1 | 160 | # if MD5_SMALL > 1 |
161 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */ | 161 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 1 */ |
162 | # endif | 162 | # endif |
163 | 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */ | 163 | 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, /* 2 */ |
@@ -171,7 +171,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
171 | uint32_t C = ctx->hash[2]; | 171 | uint32_t C = ctx->hash[2]; |
172 | uint32_t D = ctx->hash[3]; | 172 | uint32_t D = ctx->hash[3]; |
173 | 173 | ||
174 | #if MD5_SIZE_VS_SPEED >= 2 /* 2 or 3 */ | 174 | #if MD5_SMALL >= 2 /* 2 or 3 */ |
175 | 175 | ||
176 | static const char S_array[] ALIGN1 = { | 176 | static const char S_array[] ALIGN1 = { |
177 | 7, 12, 17, 22, | 177 | 7, 12, 17, 22, |
@@ -190,7 +190,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
190 | words[i] = SWAP_LE32(words[i]); | 190 | words[i] = SWAP_LE32(words[i]); |
191 | # endif | 191 | # endif |
192 | 192 | ||
193 | # if MD5_SIZE_VS_SPEED == 3 | 193 | # if MD5_SMALL == 3 |
194 | pc = C_array; | 194 | pc = C_array; |
195 | pp = P_array; | 195 | pp = P_array; |
196 | ps = S_array - 4; | 196 | ps = S_array - 4; |
@@ -220,7 +220,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
220 | C = B; | 220 | C = B; |
221 | B = temp; | 221 | B = temp; |
222 | } | 222 | } |
223 | # else /* MD5_SIZE_VS_SPEED == 2 */ | 223 | # else /* MD5_SMALL == 2 */ |
224 | pc = C_array; | 224 | pc = C_array; |
225 | pp = P_array; | 225 | pp = P_array; |
226 | ps = S_array; | 226 | ps = S_array; |
@@ -271,13 +271,13 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
271 | ctx->hash[2] += C; | 271 | ctx->hash[2] += C; |
272 | ctx->hash[3] += D; | 272 | ctx->hash[3] += D; |
273 | 273 | ||
274 | #else /* MD5_SIZE_VS_SPEED == 0 or 1 */ | 274 | #else /* MD5_SMALL == 0 or 1 */ |
275 | 275 | ||
276 | uint32_t A_save = A; | 276 | uint32_t A_save = A; |
277 | uint32_t B_save = B; | 277 | uint32_t B_save = B; |
278 | uint32_t C_save = C; | 278 | uint32_t C_save = C; |
279 | uint32_t D_save = D; | 279 | uint32_t D_save = D; |
280 | # if MD5_SIZE_VS_SPEED == 1 | 280 | # if MD5_SMALL == 1 |
281 | const uint32_t *pc; | 281 | const uint32_t *pc; |
282 | const char *pp; | 282 | const char *pp; |
283 | int i; | 283 | int i; |
@@ -299,7 +299,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
299 | } while (0) | 299 | } while (0) |
300 | 300 | ||
301 | /* Round 1 */ | 301 | /* Round 1 */ |
302 | # if MD5_SIZE_VS_SPEED == 1 | 302 | # if MD5_SMALL == 1 |
303 | pc = C_array; | 303 | pc = C_array; |
304 | for (i = 0; i < 4; i++) { | 304 | for (i = 0; i < 4; i++) { |
305 | OP(A, B, C, D, 7, *pc++); | 305 | OP(A, B, C, D, 7, *pc++); |
@@ -339,7 +339,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
339 | } while (0) | 339 | } while (0) |
340 | 340 | ||
341 | /* Round 2 */ | 341 | /* Round 2 */ |
342 | # if MD5_SIZE_VS_SPEED == 1 | 342 | # if MD5_SMALL == 1 |
343 | pp = P_array; | 343 | pp = P_array; |
344 | for (i = 0; i < 4; i++) { | 344 | for (i = 0; i < 4; i++) { |
345 | OP(FG, A, B, C, D, (int) (*pp++), 5, *pc++); | 345 | OP(FG, A, B, C, D, (int) (*pp++), 5, *pc++); |
@@ -367,7 +367,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
367 | # endif | 367 | # endif |
368 | 368 | ||
369 | /* Round 3 */ | 369 | /* Round 3 */ |
370 | # if MD5_SIZE_VS_SPEED == 1 | 370 | # if MD5_SMALL == 1 |
371 | for (i = 0; i < 4; i++) { | 371 | for (i = 0; i < 4; i++) { |
372 | OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++); | 372 | OP(FH, A, B, C, D, (int) (*pp++), 4, *pc++); |
373 | OP(FH, D, A, B, C, (int) (*pp++), 11, *pc++); | 373 | OP(FH, D, A, B, C, (int) (*pp++), 11, *pc++); |
@@ -394,7 +394,7 @@ static void FAST_FUNC md5_process_block64(md5_ctx_t *ctx) | |||
394 | # endif | 394 | # endif |
395 | 395 | ||
396 | /* Round 4 */ | 396 | /* Round 4 */ |
397 | # if MD5_SIZE_VS_SPEED == 1 | 397 | # if MD5_SMALL == 1 |
398 | for (i = 0; i < 4; i++) { | 398 | for (i = 0; i < 4; i++) { |
399 | OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++); | 399 | OP(FI, A, B, C, D, (int) (*pp++), 6, *pc++); |
400 | OP(FI, D, A, B, C, (int) (*pp++), 10, *pc++); | 400 | OP(FI, D, A, B, C, (int) (*pp++), 10, *pc++); |
diff --git a/libbb/hash_md5prime.c b/libbb/hash_md5prime.c index 7986f4d29..e089a15f5 100644 --- a/libbb/hash_md5prime.c +++ b/libbb/hash_md5prime.c | |||
@@ -59,7 +59,7 @@ | |||
59 | * Completely removed static PADDING array. | 59 | * Completely removed static PADDING array. |
60 | * | 60 | * |
61 | * Reintroduced the loop unrolling in md5_transform and added the | 61 | * Reintroduced the loop unrolling in md5_transform and added the |
62 | * MD5_SIZE_VS_SPEED option for configurability. Define below as: | 62 | * MD5_SMALL option for configurability. Define below as: |
63 | * 0 fully unrolled loops | 63 | * 0 fully unrolled loops |
64 | * 1 partially unrolled (4 ops per loop) | 64 | * 1 partially unrolled (4 ops per loop) |
65 | * 2 no unrolling -- introduces the need to swap 4 variables (slow) | 65 | * 2 no unrolling -- introduces the need to swap 4 variables (slow) |
@@ -75,12 +75,12 @@ | |||
75 | #include "libbb.h" | 75 | #include "libbb.h" |
76 | 76 | ||
77 | /* 1: fastest, 3: smallest */ | 77 | /* 1: fastest, 3: smallest */ |
78 | #if CONFIG_MD5_SIZE_VS_SPEED < 1 | 78 | #if CONFIG_MD5_SMALL < 1 |
79 | # define MD5_SIZE_VS_SPEED 1 | 79 | # define MD5_SMALL 1 |
80 | #elif CONFIG_MD5_SIZE_VS_SPEED > 3 | 80 | #elif CONFIG_MD5_SMALL > 3 |
81 | # define MD5_SIZE_VS_SPEED 3 | 81 | # define MD5_SMALL 3 |
82 | #else | 82 | #else |
83 | # define MD5_SIZE_VS_SPEED CONFIG_MD5_SIZE_VS_SPEED | 83 | # define MD5_SMALL CONFIG_MD5_SMALL |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | #if BB_LITTLE_ENDIAN | 86 | #if BB_LITTLE_ENDIAN |
@@ -152,7 +152,7 @@ memcpy32_le2cpu(uint32_t *output, const unsigned char *input, unsigned len) | |||
152 | static void md5_transform(uint32_t state[4], const unsigned char block[64]) | 152 | static void md5_transform(uint32_t state[4], const unsigned char block[64]) |
153 | { | 153 | { |
154 | uint32_t a, b, c, d, x[16]; | 154 | uint32_t a, b, c, d, x[16]; |
155 | #if MD5_SIZE_VS_SPEED > 1 | 155 | #if MD5_SMALL > 1 |
156 | uint32_t temp; | 156 | uint32_t temp; |
157 | const unsigned char *ps; | 157 | const unsigned char *ps; |
158 | 158 | ||
@@ -162,9 +162,9 @@ static void md5_transform(uint32_t state[4], const unsigned char block[64]) | |||
162 | 4, 11, 16, 23, | 162 | 4, 11, 16, 23, |
163 | 6, 10, 15, 21 | 163 | 6, 10, 15, 21 |
164 | }; | 164 | }; |
165 | #endif /* MD5_SIZE_VS_SPEED > 1 */ | 165 | #endif /* MD5_SMALL > 1 */ |
166 | 166 | ||
167 | #if MD5_SIZE_VS_SPEED > 0 | 167 | #if MD5_SMALL > 0 |
168 | const uint32_t *pc; | 168 | const uint32_t *pc; |
169 | const unsigned char *pp; | 169 | const unsigned char *pp; |
170 | int i; | 170 | int i; |
@@ -198,7 +198,7 @@ static void md5_transform(uint32_t state[4], const unsigned char block[64]) | |||
198 | 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */ | 198 | 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 /* 4 */ |
199 | }; | 199 | }; |
200 | 200 | ||
201 | #endif /* MD5_SIZE_VS_SPEED > 0 */ | 201 | #endif /* MD5_SMALL > 0 */ |
202 | 202 | ||
203 | memcpy32_le2cpu(x, block, 64); | 203 | memcpy32_le2cpu(x, block, 64); |
204 | 204 | ||
@@ -207,7 +207,7 @@ static void md5_transform(uint32_t state[4], const unsigned char block[64]) | |||
207 | c = state[2]; | 207 | c = state[2]; |
208 | d = state[3]; | 208 | d = state[3]; |
209 | 209 | ||
210 | #if MD5_SIZE_VS_SPEED > 2 | 210 | #if MD5_SMALL > 2 |
211 | pc = C; | 211 | pc = C; |
212 | pp = P; | 212 | pp = P; |
213 | ps = S - 4; | 213 | ps = S - 4; |
@@ -233,7 +233,7 @@ static void md5_transform(uint32_t state[4], const unsigned char block[64]) | |||
233 | temp += b; | 233 | temp += b; |
234 | a = d; d = c; c = b; b = temp; | 234 | a = d; d = c; c = b; b = temp; |
235 | } | 235 | } |
236 | #elif MD5_SIZE_VS_SPEED > 1 | 236 | #elif MD5_SMALL > 1 |
237 | pc = C; | 237 | pc = C; |
238 | pp = P; | 238 | pp = P; |
239 | ps = S; | 239 | ps = S; |
@@ -260,7 +260,7 @@ static void md5_transform(uint32_t state[4], const unsigned char block[64]) | |||
260 | II(a, b, c, d, x[*pp], ps[i & 0x3], *pc); pp++; pc++; | 260 | II(a, b, c, d, x[*pp], ps[i & 0x3], *pc); pp++; pc++; |
261 | temp = d; d = c; c = b; b = a; a = temp; | 261 | temp = d; d = c; c = b; b = a; a = temp; |
262 | } | 262 | } |
263 | #elif MD5_SIZE_VS_SPEED > 0 | 263 | #elif MD5_SMALL > 0 |
264 | pc = C; | 264 | pc = C; |
265 | pp = P; | 265 | pp = P; |
266 | /* Round 1 */ | 266 | /* Round 1 */ |