aboutsummaryrefslogtreecommitdiff
path: root/lib/pairing.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pairing.ml')
-rw-r--r--lib/pairing.ml52
1 files changed, 27 insertions, 25 deletions
diff --git a/lib/pairing.ml b/lib/pairing.ml
index 0ad5028..ef67901 100644
--- a/lib/pairing.ml
+++ b/lib/pairing.ml
@@ -61,30 +61,32 @@ struct
let m = F.((yq - yp) / (xq - xp)) in
F.((m * (xr - xp)) - (yr - yp))
- let e' p q =
- if G1.(equal p inf) || G2.(equal q inf) then F.one
- else
- let ate_loop = Lazy.force ate_loop in
- let _, f =
- Array.fold_left
- (fun (r, f) bit ->
- let t = line r r p in
- let f' = F.(f * f * t) in
- let r' = G2.add r r in
- if bit then
- let t = line r' q p in
- let f'' = F.(f' * t) in
- let r'' = G2.add r' q in
- (r'', f'')
- else (r', f'))
- (q, F.one) ate_loop
- in
- f
-
- let e p q =
- let t = e' p q in
- let exp = Lazy.force final_exponent in
- F.pow t exp
+ let pairing pairs =
+ let ate_loop = Lazy.force ate_loop in
+ let final_exponent = Lazy.force final_exponent in
+ let el = List.map (fun (p, q) -> (p, q, ref q)) pairs |> Array.of_list in
+ let f =
+ Array.fold_left
+ (fun f bit ->
+ let f = F.(f * f) in
+ Array.fold_left
+ (fun f (p, q, r) ->
+ let t = line !r !r p in
+ let f = F.(f * t) in
+ r := G2.add !r !r;
+ if bit then (
+ let t = line !r q p in
+ let f = F.(f * t) in
+ r := G2.add !r q;
+ f)
+ else f)
+ f el)
+ F.one ate_loop
+ in
+ F.pow f final_exponent
+
+ let e p q = pairing [ (p, q) ]
+ let check pairs = pairing pairs |> Gt.(equal id)
end
module P = Make (struct
@@ -122,5 +124,5 @@ module G1 = P.G1
module G2 = P.G2
module Gt = P.Gt
-let e' = P.e'
let e = P.e
+let check = P.check