summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-13 12:55:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-13 12:55:11 +0000
commit6bd54d48f44b65464dd637add13292ca8189e1ef (patch)
tree60f554b0a7ec2c53a58d4a43118d9686a244cc7c
parent6b1e3d7e734f85a08c2e4414764f03a7f880b3e6 (diff)
libbb/pw_encrypt_sha: -28 bytes
-rw-r--r--libbb/pw_encrypt_sha.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/libbb/pw_encrypt_sha.c b/libbb/pw_encrypt_sha.c
index 08b064750..3dbaeabc9 100644
--- a/libbb/pw_encrypt_sha.c
+++ b/libbb/pw_encrypt_sha.c
@@ -196,25 +196,23 @@ do { \
resptr = to64(resptr, w, N); \
} while (0)
if (is_sha512 == '5') {
- unsigned i = 0;
- unsigned j = 10;
- unsigned k = 20;
- /* strange swap of one byte (see below why) */
- unsigned char alt_result_31 = alt_result[31];
- alt_result[31] = alt_result[1];
+ int i = 0;
+ int j = 10;
+ int k = 20;
while (1) {
b64_from_24bit(alt_result[i], alt_result[j], alt_result[k], 4);
if (i == 9)
break;
- i += 21; i = (((i >> 4) & 2) + i) & 0x1f;
- j += 21; j = (((j >> 4) & 2) + j) & 0x1f;
- k += 21; k = (((k >> 4) & 2) + k) & 0x1f;
+ /* if x - 9 produces < 0, subtract 2 more:
+ * ((i >> 8) << 1) is either 0 or binary 111111...1110 */
+ i -= 9; i = (i & 0x1f) + ((i >> 8) << 1);
+ j -= 9; j = (j & 0x1f) + ((j >> 8) << 1);
+ k -= 9; k = (k & 0x1f) + ((k >> 8) << 1);
}
- b64_from_24bit(0, alt_result_31, alt_result[30], 3);
+ b64_from_24bit(0, alt_result[31], alt_result[30], 3);
/* was:
b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4);
b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4);
- ...............................^^^^^^^^^^^^^ why [1] and not [31]?
b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4);
b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4);
b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4);