Path: blob/master/shared/small_roots/herrmann_may.py
2589 views
import logging12from sage.all import ZZ34from shared import small_roots567def modular_bivariate(f, e, m, t, X, Y, roots_method="groebner"):8"""9Computes small modular roots of a bivariate polynomial.10More information: Herrmann M., May A., "Maximizing Small Root Bounds by Linearization and Applications to Small Secret Exponent RSA"11:param f: the polynomial12:param e: 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 x roots16:param Y: an approximate bound on the y roots17:param roots_method: the method to use to find roots (default: "groebner")18:return: a generator generating small roots (tuples of x and y roots) of the polynomial19"""20f = f.change_ring(ZZ)2122pr = ZZ["x", "y", "u"]23x, y, u = pr.gens()24qr = pr.quotient(1 + x * y - u)25U = X * Y2627logging.debug("Generating shifts...")2829shifts = []30for k in range(m + 1):31for i in range(m - k + 1):32g = x ** i * f ** k * e ** (m - k)33g = qr(g).lift()34shifts.append(g)3536for j in range(1, t + 1):37for k in range(m // t * j, m + 1):38h = y ** j * f ** k * e ** (m - k)39h = qr(h).lift()40shifts.append(h)4142L, monomials = small_roots.create_lattice(pr, shifts, [X, Y, U])43L = small_roots.reduce_lattice(L)4445pr = f.parent()46x, y = pr.gens()4748polynomials = small_roots.reconstruct_polynomials(L, f, None, monomials, [X, Y, U], preprocess_polynomial=lambda p: p(x, y, 1 + x * y))49for roots in small_roots.find_roots(pr, polynomials, method=roots_method):50yield roots[x], roots[y]515253