Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jack4818
GitHub Repository: jack4818/Castryck-Decru-SageMath
Path: blob/main/public_values_aux.py
323 views
1
from sage.all import ZZ, randint
2
3
p = None
4
5
def generate_distortion_map(E):
6
if E.a_invariants() != (0,6,0,1,0):
7
raise NotImplementedError
8
return E.isogeny(E.lift_x(ZZ(1)), codomain=E)
9
10
def generate_torsion_points(E, a, b):
11
def get_l_torsion_basis(E, l):
12
n = (p+1) // l
13
return (n*G for G in E.gens())
14
15
P2, Q2 = get_l_torsion_basis(E, 2**a)
16
P3, Q3 = get_l_torsion_basis(E, 3**b)
17
18
return P2, Q2, P3, Q3
19
20
def check_torsion_points(E, a, b, P2, Q2, P3, Q3):
21
# Make sure Torsion points are
22
# generated correctly
23
infty = E(0)
24
assert 2**(a-1)*P2 != infty
25
assert 3**(b-1)*P3 != infty
26
assert P2.weil_pairing(Q2, 2**a)**(2**(a-1)) != 1
27
assert P3.weil_pairing(Q3, 3**b)**(3**(b-1)) != 1
28
29
def gen_bob_keypair(E_start, b, P2, Q2, P3, Q3):
30
# generate challenge key
31
bobs_key = randint(0,3**b)
32
K = P3 + bobs_key*Q3
33
phi = E_start.isogeny(K, algorithm="factored")
34
EB = phi.codomain()
35
EB.set_order((p+1)**2, num_checks=0)
36
37
PB, QB = phi(P2), phi(Q2)
38
39
return bobs_key, EB, PB, QB
40
41