aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-15 20:59:32 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-15 20:59:32 +0100
commit16e7f697f8064a4e5fc2f8e181fe6a7b9602b1b3 (patch)
treee9bf4f43c76904ffa299915541eec40e9a5ce8e4
parentb8935d00b0a60be24ee9073349c2a185cebbacd4 (diff)
downloadbusybox-w32-16e7f697f8064a4e5fc2f8e181fe6a7b9602b1b3.tar.gz
busybox-w32-16e7f697f8064a4e5fc2f8e181fe6a7b9602b1b3.tar.bz2
busybox-w32-16e7f697f8064a4e5fc2f8e181fe6a7b9602b1b3.zip
libbb: eliminate redundant variable in sha_crypt
function old new delta sha_crypt 1136 1130 -6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/pw_encrypt_sha.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/libbb/pw_encrypt_sha.c b/libbb/pw_encrypt_sha.c
index 8aeaacad6..72e37e485 100644
--- a/libbb/pw_encrypt_sha.c
+++ b/libbb/pw_encrypt_sha.c
@@ -47,16 +47,17 @@ sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
47 unsigned cnt; 47 unsigned cnt;
48 unsigned rounds; 48 unsigned rounds;
49 char *cp; 49 char *cp;
50 char is_sha512;
51 50
52 /* Analyze salt, construct already known part of result */ 51 /* Analyze salt, construct already known part of result */
53 cnt = strlen(salt_data) + 1 + 43 + 1; 52 cnt = strlen(salt_data) + 1 + 43 + 1;
54 is_sha512 = salt_data[1]; 53 _32or64 = 32;
55 if (is_sha512 == '6') 54 if (salt_data[1] == '6') { /* sha512 */
55 _32or64 *= 2; /*64*/
56 cnt += 43; 56 cnt += 43;
57 }
57 result = resptr = xzalloc(cnt); /* will provide NUL terminator */ 58 result = resptr = xzalloc(cnt); /* will provide NUL terminator */
58 *resptr++ = '$'; 59 *resptr++ = '$';
59 *resptr++ = is_sha512; 60 *resptr++ = salt_data[1];
60 *resptr++ = '$'; 61 *resptr++ = '$';
61 rounds = ROUNDS_DEFAULT; 62 rounds = ROUNDS_DEFAULT;
62 salt_data += 3; 63 salt_data += 3;
@@ -93,12 +94,10 @@ sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
93 sha_begin = (void*)sha256_begin; 94 sha_begin = (void*)sha256_begin;
94 sha_hash = (void*)sha256_hash; 95 sha_hash = (void*)sha256_hash;
95 sha_end = (void*)sha256_end; 96 sha_end = (void*)sha256_end;
96 _32or64 = 32; 97 if (_32or64 != 32) {
97 if (is_sha512 == '6') {
98 sha_begin = (void*)sha512_begin; 98 sha_begin = (void*)sha512_begin;
99 sha_hash = (void*)sha512_hash; 99 sha_hash = (void*)sha512_hash;
100 sha_end = (void*)sha512_end; 100 sha_end = (void*)sha512_end;
101 _32or64 = 64;
102 } 101 }
103 102
104 /* Add KEY, SALT. */ 103 /* Add KEY, SALT. */
@@ -200,7 +199,7 @@ do { \
200 unsigned w = ((B2) << 16) | ((B1) << 8) | (B0); \ 199 unsigned w = ((B2) << 16) | ((B1) << 8) | (B0); \
201 resptr = to64(resptr, w, N); \ 200 resptr = to64(resptr, w, N); \
202} while (0) 201} while (0)
203 if (is_sha512 == '5') { 202 if (_32or64 == 32) { /* sha256 */
204 unsigned i = 0; 203 unsigned i = 0;
205 while (1) { 204 while (1) {
206 unsigned j = i + 10; 205 unsigned j = i + 10;