Debian Codegraph @

src/Spec/CompleteEdwardsCurve.v

raw
1 Require Crypto.Curves.Edwards.Pre.
2 Require Crypto.Util.Decidable.
3
4 Module E.
5 Section TwistedEdwardsCurves.
6 (* Twisted Edwards curves with complete addition laws. References:
7 * <https://eprint.iacr.org/2008/013.pdf>
8 * <http://ed25519.cr.yp.to/ed25519-20110926.pdf>
9 * <https://eprint.iacr.org/2015/677.pdf>
10 *)
11
12 Context {F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv}
13 {field:@Algebra.Hierarchy.field F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv}
14 {char_ge_3 : @Ring.char_ge F Feq Fzero Fone Fopp Fadd Fsub Fmul (BinNat.N.succ_pos BinNat.N.two)}
15 {Feq_dec:Decidable.DecidableRel Feq}.
16 Local Infix "=" := Feq : type_scope. Local Notation "a <> b" := (not (a = b)) : type_scope.
17 Local Notation "0" := Fzero. Local Notation "1" := Fone.
18 Local Infix "+" := Fadd. Local Infix "*" := Fmul.
19 Local Infix "-" := Fsub. Local Infix "/" := Fdiv.
20 Local Notation "x ^ 2" := (x*x) (at level 30).
21
22 Context {a d: F}
23 {nonzero_a : a <> 0}
24 {square_a : exists sqrt_a, sqrt_a^2 = a}
25 {nonsquare_d : forall x, x^2 <> d}.
26
27 Definition point := { xy | let '(x, y) := xy in a*x^2 + y^2 = 1 + d*x^2*y^2 }.
28 Definition coordinates (P:point) : (F*F) := let (xy, xy_onCurve_proof) := P in xy.
29 Definition eq (P Q:point) :=
30 match coordinates P, coordinates Q with
31 (x1,y1), (x2,y2) => x1 = x2 /\ y1 = y2
32 end.
33
34 Program Definition zero : point := (0, 1).
35 Next Obligation. pose Pre.onCurve_zero; eauto. Qed.
36
37 Program Definition add (P1 P2:point) : point :=
38 match coordinates P1, coordinates P2 return (F*F) with
39 (x1, y1), (x2, y2) =>
40 (((x1*y2 + y1*x2)/(1 + d*x1*x2*y1*y2)) , ((y1*y2 - a*x1*x2)/(1 - d*x1*x2*y1*y2)))
41 end.
42 Next Obligation. do 2 match goal with P : point |- _ => destruct P as [[??]?] end; eapply Pre.onCurve_add; eauto. Qed.
43
44 Fixpoint mul (n:nat) (P : point) : point :=
45 match n with
46 | O => zero
47 | S n' => add P (mul n' P)
48 end.
49 End TwistedEdwardsCurves.
50 End E.
51
52 Declare Scope E_scope.
53 Delimit Scope E_scope with E.
54 Infix "=" := E.eq : E_scope.
55 Infix "+" := E.add : E_scope.
56 Infix "*" := E.mul : E_scope.