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