Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/shared/small_roots/nitaj_fouotsa.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_trivariate(f, e, m, t, X, Y, Z, roots_method="groebner"):
9
"""
10
Computes small modular roots of a trivariate polynomial.
11
More information: Nitaj A., Fouotsa E., "A New Attack on RSA and Demytko's Elliptic Curve Cryptosystem" (Section 3)
12
:param f: the polynomial
13
:param e: the modulus
14
:param m: the parameter m
15
:param t: the parameter t
16
:param X: an approximate bound on the x roots
17
:param Y: an approximate bound on the y roots
18
:param Z: an approximate bound on the z roots
19
:param roots_method: the method to use to find roots (default: "groebner")
20
:return: a generator generating small roots (tuples of x, y, and z roots) of the polynomial
21
"""
22
f = f.change_ring(ZZ)
23
pr = f.parent()
24
x, y, z = pr.gens()
25
26
logging.debug("Generating shifts...")
27
28
shifts = []
29
for k in range(m + 1):
30
for i1 in range(k, m + 1):
31
i2 = k
32
i3 = m - i1
33
g = x ** (i1 - k) * z ** i3 * f ** k * e ** (m - k)
34
shifts.append(g)
35
36
i1 = k
37
for i2 in range(k + 1, i1 + t + 1):
38
i3 = m - i1
39
h = y ** (i2 - k) * z ** i3 * f ** k * e ** (m - k)
40
shifts.append(h)
41
42
L, monomials = small_roots.create_lattice(pr, shifts, [X, Y, Z])
43
L = small_roots.reduce_lattice(L)
44
polynomials = small_roots.reconstruct_polynomials(L, f, e ** m, monomials, [X, Y, Z])
45
for roots in small_roots.find_roots(pr, polynomials, method=roots_method):
46
yield roots[x], roots[y], roots[z]
47
48