aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/pw_encrypt_sha.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/libbb/pw_encrypt_sha.c b/libbb/pw_encrypt_sha.c
index e46848b71..8aeaacad6 100644
--- a/libbb/pw_encrypt_sha.c
+++ b/libbb/pw_encrypt_sha.c
@@ -3,7 +3,7 @@
3 */ 3 */
4 4
5/* Prefix for optional rounds specification. */ 5/* Prefix for optional rounds specification. */
6static const char str_rounds[] = "rounds=%u$"; 6static const char str_rounds[] ALIGN1 = "rounds=%u$";
7 7
8/* Maximum salt string length. */ 8/* Maximum salt string length. */
9#define SALT_LEN_MAX 16 9#define SALT_LEN_MAX 16
@@ -19,8 +19,8 @@ NOINLINE
19sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data) 19sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
20{ 20{
21 void (*sha_begin)(void *ctx) FAST_FUNC; 21 void (*sha_begin)(void *ctx) FAST_FUNC;
22 void (*sha_hash)(const void *buffer, size_t len, void *ctx) FAST_FUNC; 22 void (*sha_hash)(void *ctx, const void *buffer, size_t len) FAST_FUNC;
23 void (*sha_end)(void *resbuf, void *ctx) FAST_FUNC; 23 void (*sha_end)(void *ctx, void *resbuf) FAST_FUNC;
24 int _32or64; 24 int _32or64;
25 25
26 char *result, *resptr; 26 char *result, *resptr;
@@ -103,40 +103,40 @@ sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
103 103
104 /* Add KEY, SALT. */ 104 /* Add KEY, SALT. */
105 sha_begin(&ctx); 105 sha_begin(&ctx);
106 sha_hash(key_data, key_len, &ctx); 106 sha_hash(&ctx, key_data, key_len);
107 sha_hash(salt_data, salt_len, &ctx); 107 sha_hash(&ctx, salt_data, salt_len);
108 108
109 /* Compute alternate SHA sum with input KEY, SALT, and KEY. 109 /* Compute alternate SHA sum with input KEY, SALT, and KEY.
110 The final result will be added to the first context. */ 110 The final result will be added to the first context. */
111 sha_begin(&alt_ctx); 111 sha_begin(&alt_ctx);
112 sha_hash(key_data, key_len, &alt_ctx); 112 sha_hash(&alt_ctx, key_data, key_len);
113 sha_hash(salt_data, salt_len, &alt_ctx); 113 sha_hash(&alt_ctx, salt_data, salt_len);
114 sha_hash(key_data, key_len, &alt_ctx); 114 sha_hash(&alt_ctx, key_data, key_len);
115 sha_end(alt_result, &alt_ctx); 115 sha_end(&alt_ctx, alt_result);
116 116
117 /* Add result of this to the other context. */ 117 /* Add result of this to the other context. */
118 /* Add for any character in the key one byte of the alternate sum. */ 118 /* Add for any character in the key one byte of the alternate sum. */
119 for (cnt = key_len; cnt > _32or64; cnt -= _32or64) 119 for (cnt = key_len; cnt > _32or64; cnt -= _32or64)
120 sha_hash(alt_result, _32or64, &ctx); 120 sha_hash(&ctx, alt_result, _32or64);
121 sha_hash(alt_result, cnt, &ctx); 121 sha_hash(&ctx, alt_result, cnt);
122 122
123 /* Take the binary representation of the length of the key and for every 123 /* Take the binary representation of the length of the key and for every
124 1 add the alternate sum, for every 0 the key. */ 124 1 add the alternate sum, for every 0 the key. */
125 for (cnt = key_len; cnt != 0; cnt >>= 1) 125 for (cnt = key_len; cnt != 0; cnt >>= 1)
126 if ((cnt & 1) != 0) 126 if ((cnt & 1) != 0)
127 sha_hash(alt_result, _32or64, &ctx); 127 sha_hash(&ctx, alt_result, _32or64);
128 else 128 else
129 sha_hash(key_data, key_len, &ctx); 129 sha_hash(&ctx, key_data, key_len);
130 130
131 /* Create intermediate result. */ 131 /* Create intermediate result. */
132 sha_end(alt_result, &ctx); 132 sha_end(&ctx, alt_result);
133 133
134 /* Start computation of P byte sequence. */ 134 /* Start computation of P byte sequence. */
135 /* For every character in the password add the entire password. */ 135 /* For every character in the password add the entire password. */
136 sha_begin(&alt_ctx); 136 sha_begin(&alt_ctx);
137 for (cnt = 0; cnt < key_len; ++cnt) 137 for (cnt = 0; cnt < key_len; ++cnt)
138 sha_hash(key_data, key_len, &alt_ctx); 138 sha_hash(&alt_ctx, key_data, key_len);
139 sha_end(temp_result, &alt_ctx); 139 sha_end(&alt_ctx, temp_result);
140 140
141 /* NB: past this point, raw key_data is not used anymore */ 141 /* NB: past this point, raw key_data is not used anymore */
142 142
@@ -153,8 +153,8 @@ sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
153 /* For every character in the password add the entire password. */ 153 /* For every character in the password add the entire password. */
154 sha_begin(&alt_ctx); 154 sha_begin(&alt_ctx);
155 for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt) 155 for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt)
156 sha_hash(salt_data, salt_len, &alt_ctx); 156 sha_hash(&alt_ctx, salt_data, salt_len);
157 sha_end(temp_result, &alt_ctx); 157 sha_end(&alt_ctx, temp_result);
158 158
159 /* NB: past this point, raw salt_data is not used anymore */ 159 /* NB: past this point, raw salt_data is not used anymore */
160 160
@@ -174,22 +174,22 @@ sha_crypt(/*const*/ char *key_data, /*const*/ char *salt_data)
174 174
175 /* Add key or last result. */ 175 /* Add key or last result. */
176 if ((cnt & 1) != 0) 176 if ((cnt & 1) != 0)
177 sha_hash(p_bytes, key_len, &ctx); 177 sha_hash(&ctx, p_bytes, key_len);
178 else 178 else
179 sha_hash(alt_result, _32or64, &ctx); 179 sha_hash(&ctx, alt_result, _32or64);
180 /* Add salt for numbers not divisible by 3. */ 180 /* Add salt for numbers not divisible by 3. */
181 if (cnt % 3 != 0) 181 if (cnt % 3 != 0)
182 sha_hash(s_bytes, salt_len, &ctx); 182 sha_hash(&ctx, s_bytes, salt_len);
183 /* Add key for numbers not divisible by 7. */ 183 /* Add key for numbers not divisible by 7. */
184 if (cnt % 7 != 0) 184 if (cnt % 7 != 0)
185 sha_hash(p_bytes, key_len, &ctx); 185 sha_hash(&ctx, p_bytes, key_len);
186 /* Add key or last result. */ 186 /* Add key or last result. */
187 if ((cnt & 1) != 0) 187 if ((cnt & 1) != 0)
188 sha_hash(alt_result, _32or64, &ctx); 188 sha_hash(&ctx, alt_result, _32or64);
189 else 189 else
190 sha_hash(p_bytes, key_len, &ctx); 190 sha_hash(&ctx, p_bytes, key_len);
191 191
192 sha_end(alt_result, &ctx); 192 sha_end(&ctx, alt_result);
193 } 193 }
194 194
195 /* Append encrypted password to result buffer */ 195 /* Append encrypted password to result buffer */