-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
113 lines (90 loc) · 3.3 KB
/
test.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from framework import *
from src.hvelu import *
total_cost = [0, 0, 0]
print("\n")
print("p := 0x%X;" % p)
print("fp := GF(p);")
print("P<x> := PolynomialRing(fp);");
A = [2, 4]
print("E := EllipticCurve(x^3 + 0x%X * x^2 + x);" % coeff(A))
if True:
# T_p belongs to E[pi - 1]
# T_m belongs to E[pi + 1]
T_p, T_m = full_torsion_points(A)
else:
# T_m belongs to E[pi - 1]
# T_p belongs to E[pi + 1]
T_m, T_p = full_torsion_points(A)
assert(len(L) == n)
print("// Now, we proceed by performing xISOG with input curve equals the output curve of the previous one experiment.")
for idx in range(0, n, 1):
# -------------------------------------------------------------
# Random kernel point
Tp = list(T_p)
for i in range(idx + 1, n, 1):
Tp = xMUL(Tp, A, i)
print("// l:\t%7d |" % global_L[idx], end="")
total_cost = [0, 0, 0]
if setting.verbose:
set_parameters_velu(sJ_list[idx], sI_list[idx], idx)
else:
# -------------------------------------------------------------
# Parameters sJ and sI correspond with the parameters b and b' from example 4.12 of https://eprint.iacr.org/2020/341
# These paramters are required in KPs, xISOG, and xEVAL
if global_L[idx] == 3:
b = 0
c = 0
else:
b = int(floor( sqrt(global_L[idx] - 1) / 2.0) )
c = int(floor( (global_L[idx] - 1.0) / (4.0*b) ))
set_parameters_velu(b, c, idx)
print_parameters_velu()
# -------------------------------------------------------------
# KPs procedure
set_zero_ops()
KPs(Tp, A, idx)
show_ops("Kps", 1.0, 0.0, False)
t = get_ops();
total_cost[0] += t[0]
total_cost[1] += t[1]
total_cost[2] += t[2]
# -------------------------------------------------------------
# xISOG
set_zero_ops()
B = xISOG(A, idx)
show_ops("xISOG", 1.0, 0.0, False)
t = get_ops();
total_cost[0] += t[0]
total_cost[1] += t[1]
total_cost[2] += t[2]
# -------------------------------------------------------------
# xEVAL: kernel point determined by the next isogeny evaluation
set_zero_ops()
if global_L[idx] <= HYBRID_BOUND:
T_p = xEVAL(T_p, idx)
else:
T_p = xEVAL(T_p, A)
# xEVAL bench
set_zero_ops()
if global_L[idx] <= HYBRID_BOUND:
T_m = xEVAL(T_m, idx)
else:
T_m = xEVAL(T_m, A)
show_ops("xEVAL", 1.0, 0.0, False)
t = get_ops();
total_cost[0] += t[0]
total_cost[1] += t[1]
total_cost[2] += t[2]
print("|| cost: %7d" % (total_cost[0] + total_cost[1]), end=" " )
print("|| ratio: %1.3f" % ((total_cost[0] + total_cost[1]) / (global_L[idx] + 2.0)) )
#assert(validate(B))
A = list(B)
#print("B := EllipticCurve(x^3 + 0x%X * x^2 + x);" % coeff(A))
#print("assert(Random(B) * (p + 1) eq B!0);")
#print("BOOL, Q := IsPoint(B, fp!%d/%d);" % (T_m[0], T_m[1]))
#print("assert(BOOL);")
print("\n// All the l_i's have been processed, output of xISOG corresponds with the given below")
print("B := EllipticCurve(x^3 + 0x%X * x^2 + x);" % coeff(A))
print("assert(Random(B) * (p + 1) eq B!0);")
print("\n\"If no errors were showed using magma calculator, then all experiments were successful passed!\";")
print("// copy and paste it at http://magma.maths.usyd.edu.au/calc/\n")