Files
swift-crypto/Sources/CryptoExtras
Si Beaumont e652730d73 Fix the default Scrypt memory limit (#508)
### Motivation:

If the caller passes no `maxMemory`, `KDF.Scrypt.deriveKey` sets the
limit to `128 * blockSize * rounds * parallelism` plus a page. BoringSSL
needs `128 * blockSize * (rounds + parallelism + 1)` bytes, so some
valid parameters fail with `MEMORY_LIMIT_EXCEEDED`. For example,
`rounds: 2, blockSize: 1024, parallelism: 1` gets a limit of 256 KiB
plus a page and needs 512 KiB.

### Modifications:

- Compute the default limit as `128 * blockSize * (rounds + parallelism
+ 1)` plus a page. Overflow still throws
`CryptoKitError.incorrectParameterSize`.
- Add a test for `rounds: 2, blockSize: 1024, parallelism: 1` with no
`maxMemory`, and an overflow case for `parallelism: .max`.

### Result:

The default limit covers the memory BoringSSL needs, so valid parameters
no longer fail.

Fixes #489.
2026-11-23 15:31:15 +00:00
..
2026-10-23 10:58:54 +00:00
2025-09-26 11:55:11 +01:00
2025-09-26 11:55:11 +01:00
2026-10-20 10:55:16 +02:00
2025-09-26 11:55:11 +01:00
2025-09-26 11:55:11 +01:00