4from numpy
import base_repr
18from setup
import arguments, setup_fp, setup_fq, ProgressBar
19from random_walks2
import cgl_hash2, to_mont
20from random_walks3
import cgl_hash3, get_order3_points, to_model, isogeny3
21from basefield_chain3
import radical_walk3
24if __name__ ==
'__main__':
26 setup = setup_fq(arguments(sys.argv[1:]).bits)
28 p = Fq.characteristic()
31 setup[
'j₋₁'] = EllipticCurve([0, A + 6, 0, 4 * (2 + A), 0]).j_invariant()
32 setup[
'j₀'] = EllipticCurve([0, A, 0, 1, 0]).j_invariant()
34 print(
'\033[93m#################################################### CGLHash2 with starting curve E₆ : y² = x³ + 6x² + x\033[00m\033[00m')
36 for tries
in range(0, runs, 1):
37 ProgressBar(tries + 1, runs, f
"Testing CGLHash2")
38 hash_input = hex(randrange(0, p))[2:].encode()
39 start_time = time.perf_counter()
40 j = cgl_hash2(hash_input, setup, verbose=
False)
41 end_time = time.perf_counter()
42 elapsed_time += (end_time - start_time)
44 print(f
'\nAverage time (CGLHash2): {elapsed_time / runs}\n')
46 print(
'\033[93m#################################################### CGLHash2 with random starting curve E : y² = x³ + Ax² + x\033[00m\033[00m')
48 for tries
in range(0, runs, 1):
51 setup[
'j₋₁'] = EllipticCurve([0, A + 6, 0, 4 * (2 + A), 0]).j_invariant()
52 setup[
'j₀'] = EllipticCurve([0, A, 0, 1, 0]).j_invariant()
54 ProgressBar(tries + 1, runs, f
"Testing CGLHash2")
55 hash_input = hex(randrange(0, p))[2:].encode()
56 start_time = time.perf_counter()
57 j = cgl_hash2(hash_input, setup, verbose=
False)
58 end_time = time.perf_counter()
59 elapsed_time += (end_time - start_time)
61 print(f
'\nAverage time (CGLHash2): {elapsed_time / runs}\n')
64 print(
'\033[93m#################################################### CGLHash3 with starting curve E₆ : y² = x³ + 6x² + x\033[00m\033[00m')
68 j = EllipticCurve(Fq, [a1, 0, a3, 0, 0]).j_invariant()
69 F_ = EllipticCurve(Fq, [a1, 0, a3, -5 * a1 * a3, -a1**3 * a3 - 7 * a3**2])
73 alpha = setup[
'curt'](-a3)
74 assert alpha**3 == -a3
75 a1_, a3_ = isogeny3(alpha, a1, a3)
76 j0 = EllipticCurve(Fq, [a1_, 0, a3_, -5 * a1_ * a3_, -a1_**3 * a3_ - 7 * a3_**2]).j_invariant()
79 assert alpha**3 == -a3
80 a1_, a3_ = isogeny3(alpha, a1, a3)
81 j1 = EllipticCurve(Fq, [a1_, 0, a3_, -5 * a1_ * a3_, -a1_**3 * a3_ - 7 * a3_**2]).j_invariant()
84 assert alpha**3 == -a3
85 a1_, a3_ = isogeny3(alpha, a1, a3)
86 j2 = EllipticCurve(Fq, [a1_, 0, a3_, -5 * a1_ * a3_, -a1_**3 * a3_ - 7 * a3_**2]).j_invariant()
101 xs = get_order3_points(A, setup)
103 yk = setup[
'sqrt'](xk**3 + A * xk**2 + xk)
104 a1, a3 = to_model(A, xk)
109 for tries
in range(0, runs, 1):
110 ProgressBar(tries + 1, runs, f
"Testing CGLHash3")
111 hash_input = hex(randrange(0, p))[2:].encode()
112 start_time = time.perf_counter()
113 j = cgl_hash3(hash_input, setup, verbose=
False)
114 end_time = time.perf_counter()
115 elapsed_time += (end_time - start_time)
117 print(f
'\nAverage time (CGLHash3): {elapsed_time / runs}\n')
119 print(
'\033[93m#################################################### CGLHash3 with random starting curve E : y² = x³ + Ax² + x\033[00m\033[00m')
121 for tries
in range(0, runs, 1):
123 A = to_mont(j, setup)
127 xs = get_order3_points(A, setup)
129 yk = setup[
'sqrt'](xk**3 + A * xk**2 + xk)
130 a1, a3 = to_model(A, xk)
133 ProgressBar(tries + 1, runs, f
"Testing CGLHash3")
134 hash_input = hex(randrange(0, p))[2:].encode()
135 start_time = time.perf_counter()
136 j = cgl_hash3(hash_input, setup, verbose=
False)
137 end_time = time.perf_counter()
138 elapsed_time += (end_time - start_time)
140 print(f
'\nAverage time (CGLHash3): {elapsed_time / runs}\n')
143 setup = setup_fp(arguments(sys.argv[1:]).bits)
145 p = Fp.characteristic()
147 print(
'\033[93m#################################################### Radical 3-isogeny chain with starting curve E₆ : y² = x³ + 6x² + x\033[00m\033[00m')
148 for value
in range(0, 128, 1):
149 ProgressBar(value + 1, 128, f
"Testing (+) Radical 3-isogeny over GF(p)")
150 A = radical_walk3(A, value, setup)
152 for value
in range(0, 128, 1):
153 ProgressBar(value + 1, 128, f
"Testing (-) Radical 3-isogeny over GF(p)")
154 A = radical_walk3(A, -value, setup)