Linear-relation Fermat factoring #
Formalizes Fermat factoring under a known integer linear relation |a * p - b * q| < n ^ (1 / 4)
(Boneh–Shoup Section 16.4.2.1, p. 699, and Exercise 16.14, p. 710). The book writes
|a * p + b * q| < n ^ (1 / 4) with real parameters a and b; here a and b are natural
numbers with the book's b negated, and non-integer real parameters (a, b) are out of scope.
Multiplying n = p * q by 4 * a * b pairs 2 * a * p and 2 * b * q, whose sum is always
even, so fermatFactor (4 * a * b * n) recovers (2 * a * p, 2 * b * q) up to order without any
parity side condition on a * p + b * q (by contrast, a = 3, b = 2 on odd p gives odd
3 * p + 2 * q, so ⌈√(6 * n)⌉ ≠ (3 * p + 2 * q) / 2). Taking gcds with n then recovers
(p, q) or (q, p) provided Nat.Coprime (2 * a) q and Nat.Coprime (2 * b) p (equivalently
¬ q ∣ 2 * a and ¬ p ∣ 2 * b for primes p, q). Because fermatFactor computes a single
closed-form integer square root with no gap search loop, complexity is certified directly as
ComputableInPolyTime rather than as a step bound in terms of |a * p - b * q|.
Main definitions #
fermatFactorLinear: feeds4 * a * b * ntofermatFactorand takes gcds withn.
Main results #
fermatFactor_four_mul_eq: closed-form Fermat factorization of4 * a * b * (p * q).fermatFactorLinear_mul_eq,fermatFactorLinear_mul_eq_of_lt_rpow: factor recovery under|a * p - b * q| < (4 * a * b * p * q) ^ (1 / 4)and under the book's boundn ^ (1 / 4)for positivea,b.RSADesc.fermatFactorLinear_eq_of_lt_rpow: RSA modulus wrapper using¬ desc.q ∣ 2 * aand¬ desc.p ∣ 2 * b.computableInPolyTime_fermatFactorLinear,computableInPolyTime_fermatFactorLinear_prod: polynomial-time computability certificates.
References #
- [BS23], Section 16.4.2.1 (p. 699) and Exercise 16.14 (p. 710).
Under |(a : ℝ) * p - b * q| < (4 * a * b * p * q) ^ (1 / 4), fermatFactor on
4 * a * b * (p * q) returns (2 * a * p, 2 * b * q) when b * q ≤ a * p and the swapped
pair otherwise.
fermatFactorLinear a b (p * q) recovers (p, q) when b * q ≤ a * p and (q, p)
otherwise, under Nat.Coprime (2 * a) q, Nat.Coprime (2 * b) p, and
|(a : ℝ) * p - b * q| < (4 * a * b * p * q) ^ (1 / 4).
Corollary of fermatFactorLinear_mul_eq under the textbook bound
|(a : ℝ) * p - b * q| < ((p : ℝ) * q) ^ (1 / 4 : ℝ) for positive integers a and b.
Textbook-bound RSADesc wrapper: if ¬ desc.q ∣ 2 * a, ¬ desc.p ∣ 2 * b, and
|a * desc.p - b * desc.q| < desc.modulus ^ (1 / 4), then fermatFactorLinear a b desc.modulus
recovers (desc.p, desc.q) up to order.
fermatFactorLinear is computable in polynomial time (compositionally).
fermatFactorLinear is computable in polynomial time on ((a, b), n).