blob: 1182352493a406aad6fd742fcc89a8bbbddb811f (
plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
module E = Curve.Make (struct
module F = Fields.Fp
let b = F.of_string "4"
let g =
F.
( of_string
"3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507",
of_string
"1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"
)
let n =
Z.of_string
"52435875175126190479447740508185965837690552500527637822603658699938581184513"
end)
module E2 = Curve.Make (struct
module F = Fields.Fp2
let b = F.of_string "(4,4)"
let g =
F.
( of_coeffs
Fields.Fp.
[|
of_string
"352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160";
of_string
"3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758";
|],
of_coeffs
Fields.Fp.
[|
of_string
"1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905";
of_string
"927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582";
|] )
let n = E.n
end)
module E12 = Curve.Make (struct
module F = Fields.Fp12
let b = F.of_f @@ Fields.Fp.of_string "4"
let g =
F.
( of_coeffs
Fields.Fp.
[|
zero;
zero;
zero;
zero;
of_string
"352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160";
zero;
zero;
zero;
zero;
zero;
of_string
"1353221637328373545892060349371360746048220186341936159219732281025920769516621702780080981380240920942561918531299";
zero;
|],
of_coeffs
Fields.Fp.
[|
zero;
zero;
zero;
of_string
"1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905";
zero;
zero;
zero;
zero;
zero;
of_string
"1472406309213353956798468635167385199506877017588472562248853724925831900559844855499883907296819622485916638215732";
zero;
zero;
|] )
let n = E.n
end)
let twist =
let ws =
lazy
(let w =
Fields.Fp12.of_coeffs
Fields.Fp.
[|
zero;
one;
zero;
zero;
zero;
zero;
zero;
zero;
zero;
zero;
zero;
zero;
|]
in
let w2 = Fields.Fp12.(w * w) in
let w3 = Fields.Fp12.(w2 * w) in
let w2inv = Fields.Fp12.inv w2 in
let w3inv = Fields.Fp12.inv w3 in
(w2inv, w3inv))
in
let iso a =
let c = Fields.Fp2.to_coeffs a in
Fields.Fp12.of_coeffs
Fields.Fp.
[|
Fields.Fp.(c.(0) - c.(1));
zero;
zero;
zero;
zero;
zero;
c.(1);
zero;
zero;
zero;
zero;
zero;
|]
in
fun p ->
match E2.to_coords p with
| None -> E12.inf
| Some (x, y) ->
let nx, ny = (iso x, iso y) in
let w2inv, w3inv = Lazy.force ws in
let c = Fields.Fp12.(nx * w2inv, ny * w3inv) in
E12.Unsafe.of_coords_unchecked c
|