Path: blob/master/shared/small_roots/howgrave_graham.py
2589 views
import logging12from sage.all import ZZ34from shared import small_roots567def modular_univariate(f, N, m, t, X):8"""9Computes small modular roots of a univariate polynomial.10More information: May A., "New RSA Vulnerabilities Using Lattice Reduction Methods" (Section 3.2)11:param f: the polynomial12:param N: the modulus13:param m: the amount of normal shifts to use14:param t: the amount of additional shifts to use15:param X: an approximate bound on the roots16:return: a generator generating small roots of the polynomial17"""18f = f.monic().change_ring(ZZ)19pr = f.parent()20x = pr.gen()21delta = f.degree()2223logging.debug("Generating shifts...")2425shifts = []26for i in range(m):27for j in range(delta):28g = x ** j * N ** (m - i) * f ** i29shifts.append(g)3031for i in range(t):32h = x ** i * f ** m33shifts.append(h)3435L, monomials = small_roots.create_lattice(pr, shifts, [X], order=None)36L = small_roots.reduce_lattice(L)37polynomials = small_roots.reconstruct_polynomials(L, f, N ** m, monomials, [X])38for roots in small_roots.find_roots(pr, polynomials):39yield roots[x],404142