mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
### Motivation: `extractPrimeFactors` squares `t` times per attempt, where `t` is the number of trailing zero bits of `e * d - 1`. Nothing bounds `e`, `d` or `n`, so the caller picks the cost. A 2.5 KB `d` takes about 45 s before throwing. ### Modifications: - Reject `e >= n`, `d >= n`, and moduli over 8192 bits before factoring - Throw once `g^(e * d - 1) != 1`, since then the numbers cannot form a key - Add tests for oversized and inconsistent numbers - Keep the #482 attempt-limit test reaching the limit now that `e >= n` is rejected ### Result: These inputs now throw immediately. No public API change. Valid keys aren't affected: they always have `e < n` and `d < n`, and BoringSSL already rejects moduli over 8192 bits. The oversized-number test fails on `main` and passes with this change. The RSA tests pass on macOS. Fixes #483