-
Notifications
You must be signed in to change notification settings - Fork 125
/
boneh_durfee.py
41 lines (33 loc) · 1.39 KB
/
boneh_durfee.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import logging
from sage.all import ZZ
from shared import small_roots
def modular_bivariate(f, e, m, t, X, Y, roots_method="groebner"):
"""
Computes small modular roots of a bivariate polynomial.
More information: Boneh D., Durfee G., "Cryptanalysis of RSA with Private Key d Less than N^0.292"
:param f: the polynomial
:param e: the modulus
:param m: the amount of normal shifts to use
:param t: the amount of additional shifts to use
:param X: an approximate bound on the x roots
:param Y: an approximate bound on the y roots
:param roots_method: the method to use to find roots (default: "groebner")
:return: a generator generating small roots (tuples of x and y roots) of the polynomial
"""
f = f.change_ring(ZZ)
pr = f.parent()
x, y = pr.gens()
logging.debug("Generating shifts...")
shifts = []
for k in range(m + 1):
for i in range(m - k + 1):
g = x ** i * f ** k * e ** (m - k)
shifts.append(g)
for j in range(t + 1):
h = y ** j * f ** k * e ** (m - k)
shifts.append(h)
L, monomials = small_roots.create_lattice(pr, shifts, [X, Y])
L = small_roots.reduce_lattice(L)
polynomials = small_roots.reconstruct_polynomials(L, f, e ** m, monomials, [X, Y])
for roots in small_roots.find_roots(pr, polynomials, method=roots_method):
yield roots[x], roots[y]