Skip to content

Commit ca20af9

Browse files
committed
KWallet format: Minor optimization, comments on likely bugs in old KDF
1 parent 094d8b8 commit ca20af9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/kwallet_fmt_plug.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void *get_salt(char *ciphertext)
203203
static void password2hash(const char *password, unsigned char *hash, int *key_size)
204204
{
205205
SHA_CTX ctx;
206-
unsigned char output[20 * ((PLAINTEXT_LENGTH + 15) / 16)];
206+
unsigned char output[60];
207207
unsigned char buf[20];
208208
int i, j, oindex = 0;
209209
int plength = strlen(password);
@@ -213,13 +213,16 @@ static void password2hash(const char *password, unsigned char *hash, int *key_si
213213
for (i = 0; i <= plength; i += 16) {
214214
SHA1_Init(&ctx);
215215
SHA1_Update(&ctx, password + i, MIN(plength - i, 16));
216+
SHA1_Final(buf, &ctx);
216217
// To make brute force take longer
217-
for (j = 0; j < 2000; j++) {
218-
SHA1_Final(buf, &ctx);
218+
for (j = 1; j < 2000; j++) {
219219
SHA1_Init(&ctx);
220220
SHA1_Update(&ctx, buf, 20);
221+
SHA1_Final(buf, &ctx);
221222
}
222223
memcpy(output + oindex, buf, 20);
224+
if (oindex >= 40)
225+
break;
223226
oindex += 20;
224227
}
225228

@@ -233,12 +236,13 @@ static void password2hash(const char *password, unsigned char *hash, int *key_si
233236
memcpy(hash, output, 40);
234237
*key_size = 40;
235238
}
236-
else if (plength < 48) {
239+
else if (plength < 48) { /* XXX: Untested - no test vector */
237240
// key size is 56 (20/20/16 split)
238241
memcpy(hash, output, 56);
239242
*key_size = 56;
240243
}
241-
else {
244+
else { /* XXX: Untested - no test vector */
245+
/* XXX: This truncates at exactly 48, which may be wrong */
242246
// key size is 56 (14/14/14 split)
243247
memcpy(hash + 14 * 0, output + 0, 14);
244248
memcpy(hash + 14 * 1, output + 20, 14);

0 commit comments

Comments
 (0)