Debian Codegraph @

crypto_nP/montgomery25519/ref10/montgomery.q

raw
1 :name:fe:x2:z2:x3:z3:tmp0:tmp1:
2 fe r:var/r=fe:
3
4 enter f:enter/f:>X2=fe#1:>Z2=fe#2:>X3=fe#3:>Z3=fe#4:
5 return:nofallthrough:<X4=fe#1:<Z4=fe#2:<X5=fe#3:<Z5=fe#4:leave:
6
7 h=f+g:<f=fe:<g=fe:>h=fe:asm/fe_add(>h,<f,<g);:
8 h=f-g:<f=fe:<g=fe:>h=fe:asm/fe_sub(>h,<f,<g);:
9 h=f*g:<f=fe:<g=fe:>h=fe:asm/fe_mul(>h,<f,<g);:
10 h=f^2:<f=fe:>h=fe:asm/fe_sq(>h,<f);:
11
12 h=X1*g:<g=fe:>h=fe:asm/fe_mul(>h,x1,<g);:
13 h=a24*g:<g=fe:>h=fe:asm/fe_mul121666(>h,<g);:
14
15 assign x2 to h:<h=fe#1:
16 assign z2 to h:<h=fe#2:
17 assign x3 to h:<h=fe#3:
18 assign z3 to h:<h=fe#4:
19
20 :
21
22 fe X2
23 fe Z2
24 fe X3
25 fe Z3
26 fe X4
27 fe Z4
28 fe X5
29 fe Z5
30 fe A
31 fe B
32 fe C
33 fe D
34 fe E
35 fe AA
36 fe BB
37 fe DA
38 fe CB
39 fe t0
40 fe t1
41 fe t2
42 fe t3
43 fe t4
44
45 enter ladder
46
47 # http://hyperelliptic.org/EFD/g1p/auto-code/montgom/xz/ladder/mladd-1987-m.op3
48 # reordered to fit into 2 temporaries
49
50 D = X3-Z3
51 B = X2-Z2
52 A = X2+Z2
53 C = X3+Z3
54 DA = D*A
55 CB = C*B
56 BB = B^2
57 AA = A^2
58 t0 = DA+CB
59 assign x3 to t0
60 t1 = DA-CB
61 X4 = AA*BB
62 E = AA-BB
63 t2 = t1^2
64 t3 = a24*E
65 X5 = t0^2
66 t4 = BB+t3
67 Z5 = X1*t2
68 Z4 = E*t4
69
70 # double-check against Theorem B.1 in Curve25519 paper:
71 # X4-(X2^2-Z2^2)^2
72 # Z4-4*X2*Z2*(X2^2+(4*a24-2)*X2*Z2+Z2^2)
73 # X5-4*(X2*X3-Z2*Z3)^2
74 # Z5-4*(X2*Z3-Z2*X3)^2*X1
75
76 return