Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
random_walks2.py
Go to the documentation of this file.
1
import
hashlib
2
3
# SageMath imports
4
from
sage.all
import
(
5
EllipticCurve,
6
)
7
8
9
10
def
to_mont
(j, setup):
11
Fq = setup[
'Fq'
]
12
Rx = setup[
'Rx'
]
13
x = Rx.gens()[0]
14
p = Fq.characteristic()
15
16
choices = (j*(x**2 - 4) - 256*((x**2 - 3)**3)).roots()
17
good = choices != []
18
19
for
(r,_)
in
choices:
20
A = r
21
Ea = EllipticCurve(Fq, [0, A, 0, 1, 0])
22
good = good
and
(Ea.random_point() * (p + 1) == Ea(0))
23
24
assert
(good)
25
return
A
26
27
28
29
def
random_walk2
(j0_prev, j0, path, setup):
30
Fq = setup[
'Fq'
]
31
Rx = setup[
'Rx'
]
32
one_half = 1 / Fq(2)
33
34
jk = j0
35
jk_prev = j0_prev
36
for
k
in
range(0, len(path), 1):
37
Dk = jk**4 - 2976*(jk**3) + 2*(jk**2)*jk_prev + 2532192*(jk**2) - 2976*jk*jk_prev - 645205500*jk - 3*(jk_prev**2) + 324000*jk_prev - 8748000000
38
Dk_sqrt = setup[
'sqrt'
](Dk, check=
False
)
39
Dk_sqrts = [Dk_sqrt, -Dk_sqrt]
40
jk_next = (jk**2 - 1488*jk - jk_prev + 162000 + Dk_sqrts[path[k]]) * one_half
41
jk_prev = jk
42
jk = jk_next
43
44
return
jk
45
46
47
48
def
cgl_hash2
(message, setup, verbose=True):
49
p = setup[
'Fq'
].characteristic()
50
51
# SHAKE_256 algorithm from the hashlib module.
52
s = hashlib.shake_256()
53
s.update(message)
54
digest = s.hexdigest(p.bit_length() // 8)
55
path = bin(int(digest, 16))[2:p.bit_length() + 2]
56
57
if
verbose:
58
print(
'\nCGL Hash function over the 2-isogeny graph (CGLHash2)'
)
59
print(f
'Symmetric primitive:\t{s.name}'
)
60
print(f
'Message digest size:\t{len(digest) // 2} bytes'
)
61
print(f
'Random path of size:\t{len(path)} steps'
)
62
63
jE =
random_walk2
(setup[
'jāā'
], setup[
'jā'
], [ int(b)
for
b
in
path ], setup)
64
return
jE
assert
assert(var1 eq var2)
random_walks2.random_walk2
random_walk2(j0_prev, j0, path, setup)
Definition
random_walks2.py:29
random_walks2.cgl_hash2
cgl_hash2(message, setup, verbose=True)
Charles-Goren-Lauter (CGL) Hash function concerning 2-isogeny walks.
Definition
random_walks2.py:48
random_walks2.to_mont
to_mont(j, setup)
Definition
random_walks2.py:10
all
E:
pqc-engineering-ssec-23
high-level-scripts
random_walks2.py
Generated by
1.14.0