Debian Codegraph @

src/Curves/Edwards/Pre.v

raw
1 From Coq Require Import Morphisms. Require Setoid Crypto.Util.Relations.
2 Require Import Crypto.Algebra.Hierarchy Crypto.Algebra.Ring Crypto.Algebra.Field.
3 Require Import Crypto.Util.Notations Crypto.Util.Decidable (*Crypto.Util.Tactics*).
4 From Coq Require Import BinPos.
5
6 Section Edwards.
7 Context {F eq zero one opp add sub mul inv div}
8 {field:@Algebra.Hierarchy.field F eq zero one opp add sub mul inv div}
9 {eq_dec:DecidableRel eq}.
10
11 Local Infix "=" := eq. Local Notation "a <> b" := (not (a = b)).
12 Local Infix "=" := eq : type_scope. Local Notation "a <> b" := (not (a = b)) : type_scope.
13 Local Notation "0" := zero. Local Notation "1" := one.
14 Local Infix "+" := add. Local Infix "*" := mul.
15 Local Infix "-" := sub. Local Infix "/" := div.
16 Local Notation "x ^ 2" := (x*x).
17
18 Context (a:F) (a_nonzero : a<>0) (a_square : exists sqrt_a, sqrt_a^2 = a).
19 Context (d:F) (d_nonsquare : forall sqrt_d, sqrt_d^2 <> d).
20 Context {char_ge_3:@Ring.char_ge F eq zero one opp add sub mul 3}.
21
22 Local Notation onCurve x y := (a*x^2 + y^2 = 1 + d*x^2*y^2) (only parsing).
23 Lemma onCurve_zero : onCurve 0 1.
24 Proof using a_nonzero eq_dec field.
25 fsatz. Qed.
26
27 Section Addition.
28 Context (x1 y1:F) (P1onCurve: onCurve x1 y1).
29 Context (x2 y2:F) (P2onCurve: onCurve x2 y2).
30 Lemma denominator_nonzero : (d*x1*x2*y1*y2)^2 <> 1.
31 Proof using Type*.
32 destruct a_square as [sqrt_a], (dec(sqrt_a*x2+y2 = 0)), (dec(sqrt_a*x2-y2 = 0));
33 try match goal with [H: ?f (sqrt_a * x2) y2 <> 0 |- _ ]
34 => pose proof (d_nonsquare ((f (sqrt_a * x1) (d * x1 * x2 * y1 * y2 * y1))
35 /(f (sqrt_a * x2) y2 * x1 * y1 )))
36 end; Field.fsatz.
37 Qed.
38
39 Lemma denominator_nonzero_x : 1 + d*x1*x2*y1*y2 <> 0.
40 Proof using Type*. pose proof denominator_nonzero. Field.fsatz. Qed.
41 Lemma denominator_nonzero_y : 1 - d*x1*x2*y1*y2 <> 0.
42 Proof using Type*. pose proof denominator_nonzero. Field.fsatz. Qed.
43 Lemma onCurve_add : onCurve ((x1*y2 + y1*x2)/(1 + d*x1*x2*y1*y2)) ((y1*y2 - a*x1*x2)/(1 - d*x1*x2*y1*y2)).
44 Proof using Type*. pose proof denominator_nonzero. Field.fsatz. Qed.
45 End Addition.
46 End Edwards.