Skip to content

Commit

Permalink
Armory format: Support only lookup table sizes that are powers of 2
Browse files Browse the repository at this point in the history
  • Loading branch information
solardiz committed Jan 9, 2024
1 parent c52f9c8 commit 0bdfbf0
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/armory_fmt_plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void *get_salt(char *ciphertext)
salt.iter_count = JOHNSWAP(salt.iter_count);
#endif

if ((salt.bytes_reqd & 63) || salt.bytes_reqd < 128)
if (salt.bytes_reqd < 1024 || (salt.bytes_reqd & (salt.bytes_reqd - 1)))
return NULL;

CRC32_t ctx;
Expand Down Expand Up @@ -218,7 +218,6 @@ static int derive_key(region_t *memory, char *key, const struct custom_salt *sal
size_t mklen = strlen(key);

uint32_t n = salt->bytes_reqd >> 6;
uint32_t nrec = (n & (n - 1)) ? 0xffffffffU / n : 0;
uint32_t i = salt->iter_count;
do {
lut_item *p;
Expand All @@ -243,14 +242,7 @@ static int derive_key(region_t *memory, char *key, const struct custom_salt *sal
#if !ARCH_LITTLE_ENDIAN
v = JOHNSWAP(v);
#endif
if (nrec) {
v -= (((uint64_t)v * nrec) >> 32) * n;
if (v >= n)
v -= n;
} else {
v &= n - 1;
}
p = &lut[v];
p = &lut[v & (n - 1)];

uint32_t k;
for (k = 0; k < 8; k++)
Expand Down

0 comments on commit 0bdfbf0

Please sign in to comment.