mirror of
https://github.com/apple/swift-crypto
synced 2026-11-25 04:47:47 +00:00
### 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.