Documentation
¶
Overview ¶
Package cryptowedge provides implementations of classical attacks against RSA and related public-key cryptosystems.
The package is intended for security research, CTF challenges, and educational use: each attack targets a specific weakness (small private exponent, small public exponent, shared factors, and so on) and recovers key material or plaintext when that weakness is present.
Attacks ¶
Wiener implements Wiener's attack, recovering the private exponent of RSA keys with a small d (roughly d < N^(1/4)/3).
WienerLat implements a lattice-based variant of Wiener's attack, using Lagrange-Gauss lattice reduction to recover the private exponent under the same small-d condition.
Usage ¶
These functions succeed only when the targeted weakness is present; against securely generated keys they report failure rather than recovering anything. Use them only against systems you are authorized to test.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotVulnerable = errors.New("wiener: key not vulnerable to Wiener's attack") ErrInvalidKey = errors.New("wiener: invalid public key") )
Functions ¶
func Wiener ¶
Wiener attempts to recover the RSA private exponent from the public key (N, e) using Wiener's attack.
It walks the convergents of the continued fraction of e/N, and for each candidate reconstructs phi(N), solves the quadratic x^2 - (N-phi+1)x + N = 0 for the prime factors, and verifies that they reconstruct N. On success it returns the private exponent d together with the factors p and q of N.
The attack only works against keys with a small private exponent, roughly d < N^(1/4)/3. If no convergent yields a valid factorization - the usual case for a securely generated key - Wiener returns ErrNotVulnerable and the three *big.Int results are nil.
N and e must be a well-formed RSA public key with N = p*q for distinct primes p and q; behavior is unspecified for other inputs.
func WienerLat ¶ added in v0.2.0
WienerLat attempts to recover the RSA private exponent from the public key (N, e) using a lattice‑based variant of Wiener’s attack.
It constructs a 2‑dimensional lattice basis from the public key, reduces it using Lagrange‑Gauss reduction to obtain a short basis vector, and extracts the first reduced vector as the candidate for (d, -k), where k satisfies e*d - 1 = k * phi(N). It then reconstructs phi(N) by checking the divisibility of e*d - 1 by k, solves the quadratic x² - (N - phi + 1)x + N = 0 for the prime factors, and verifies that they reconstruct N. On success it returns the private exponent d together with the factors p and q of N.
The attack works under the same condition as the classical Wiener attack: it succeeds when the private exponent d is sufficiently small, roughly d < N^(1/4) / 3. If the candidate vector does not yield a valid factorization – which is the usual case for a securely generated key – WienerLat returns ErrNotVulnerable and the three *big.Int results are nil.
N and e must be a well‑formed RSA public key with N = p*q for distinct primes p and q; behavior is unspecified for other inputs.
Types ¶
This section is empty.