Skip to content

Commit 03774b0

Browse files
committed
fix(scrypt): correct maxmem calculation to use parameter p for memory allocation
1 parent 7482bfa commit 03774b0

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

app/utils/auth.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ async function generateKey(
319319
N: SCRYPT_PARAMS.N,
320320
r: SCRYPT_PARAMS.r,
321321
p: SCRYPT_PARAMS.p,
322-
maxmem: 128 * SCRYPT_PARAMS.N * SCRYPT_PARAMS.r * 2,
322+
maxmem: 128 * SCRYPT_PARAMS.N * SCRYPT_PARAMS.r * SCRYPT_PARAMS.p * 2,
323323
},
324324
(err, key) => {
325325
if (err) reject(err)

docs/decisions/045-scrypt-migration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ These parameters were chosen to:
4343
- Maintain acceptable performance characteristics
4444

4545
The actual scrypt options object includes an additional `maxmem` parameter set
46-
to `128 * N * r * 2`, which is approximately 64MiB for our parameters. This is
47-
explicitly set because Node.js has an internal default memory limit of 32 MiB.
48-
By setting this parameter, we're telling Node.js that twice the estimated memory
49-
(64 MiB) is allowed for this operation, ensuring optimal performance while
50-
maintaining security.
46+
to `128 * N * r * p * 2`, which is approximately 64MiB for our parameters. This
47+
is explicitly set because Node.js has an internal default memory limit of 32
48+
MiB. By setting this parameter, we're telling Node.js that twice the estimated
49+
memory (64 MiB) is allowed for this operation, ensuring optimal performance
50+
while maintaining security.
5151

5252
## Implementation Changes
5353

tests/db-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function createPassword(password: string = faker.internet.password()) {
3535
N: 2 ** 14,
3636
r: 16,
3737
p: 1,
38-
maxmem: 128 * 2 ** 14 * 16 * 2,
38+
maxmem: 128 * 2 ** 14 * 16 * 1 * 2,
3939
})
4040
return {
4141
hash: `${salt}:${hash.toString('hex')}`,

0 commit comments

Comments
 (0)