Debian Codegraph @

src/Curves/Edwards/TwistIsomorphism.v

raw
1 From Coq Require Import Morphisms.
2 Require Import Crypto.Algebra.Hierarchy.
3 Require Import Crypto.Algebra.Field.
4 Require Import Crypto.Spec.CompleteEdwardsCurve.
5 Require Import Crypto.Curves.Edwards.AffineProofs.
6 Require Import Crypto.Util.Tactics.BreakMatch.
7 Require Import Crypto.Util.Tactics.
8 Require Import Crypto.Util.Prod.
9
10 Module E. Section __.
11 Context {F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv}
12 {field:@field F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv}
13 {char_ge_3 : @Ring.char_ge F Feq Fzero Fone Fopp Fadd Fsub Fmul (BinNat.N.succ_pos BinNat.N.two)}
14 {Feq_dec:DecidableRel Feq}.
15 Local Infix "=" := Feq : type_scope. Local Notation "a <> b" := (not (a = b)) : type_scope.
16 Local Notation "0" := Fzero. Local Notation "1" := Fone.
17 Local Infix "+" := Fadd. Local Infix "*" := Fmul.
18 Local Infix "-" := Fsub. Local Infix "/" := Fdiv.
19 Local Notation "x ^ 2" := (x*x) (at level 30, right associativity).
20 Context {a1 d1 a2 d2 : F} {Heq : a1*d2 = a2*d1}.
21 Context {nonzero_a1 : a1 <> 0} {square_a1 : exists sqrt_a, sqrt_a^2 = a1} {nonsquare_d1 : forall x, x^2 <> d1}.
22 Context {nonzero_a2 : a2 <> 0} {square_a2 : exists sqrt_a, sqrt_a^2 = a2} {nonsquare_d2 : forall x, x^2 <> d2}.
23 Context {r : F} {Hr : a1 = r^2*a2}.
24
25 Local Notation point1 := (@E.point F Feq Fone Fadd Fmul a1 d1).
26 Local Notation point2 := (@E.point F Feq Fone Fadd Fmul a2 d2).
27
28 Definition point2_of_point1 (P : point1) : point2. refine (
29 exist _ (let '(x, y) := E.coordinates P in (x*r, y)) _).
30 abstract (case P as ((x&y)&?); cbn [E.coordinates]; fsatz).
31 Defined.
32
33 Definition point1_of_point2 (P : point2) : point1. refine (
34 exist _ (let '(x, y) := E.coordinates P in (x/r, y)) _).
35 abstract (case P as ((x&y)&?); cbn [E.coordinates]; fsatz).
36 Defined.
37
38 Global Instance Proper_point1_of_point2 : Proper (E.eq ==> E.eq) point1_of_point2.
39 Proof. cbv [point1_of_point2 E.eq E.coordinates]; repeat intro; break_match; intuition fsatz. Qed.
40 Global Instance Proper_point2_of_point1 : Proper (E.eq ==> E.eq) point2_of_point1.
41 Proof. cbv [point2_of_point1 E.eq E.coordinates]; repeat intro; break_match; intuition fsatz. Qed.
42
43 Add Field Private_field : (Algebra.Field.field_theory_for_stdlib_tactic (T:=F)).
44 Import Field_tac.
45
46 Lemma twist_isomorphism : @Group.isomorphic_commutative_groups
47 _ E.eq
48 (E.add(nonzero_a:=nonzero_a1)(square_a:=square_a1)(nonsquare_d:=nonsquare_d1))
49 (E.zero(nonzero_a:=nonzero_a1))
50 (E.opp(nonzero_a:=nonzero_a1))
51 _ E.eq
52 (E.add(nonzero_a:=nonzero_a2)(square_a:=square_a2)(nonsquare_d:=nonsquare_d2))
53 (E.zero(nonzero_a:=nonzero_a2))
54 (E.opp(nonzero_a:=nonzero_a2))
55 point2_of_point1 point1_of_point2.
56 Proof.
57 unshelve epose proof E.edwards_curve_commutative_group(a:=a1)(d:=d1) as G1; trivial.
58 unshelve epose proof E.edwards_curve_commutative_group(a:=a2)(d:=d2) as G2; trivial.
59 esplit; trivial; [|]; split; try exact _;
60 intros ((x&y)&?) ((x'&y')&?); case square_a1 as (r1&?), square_a2 as (r2&?);
61 cbv [point2_of_point1 point1_of_point2 E.add E.eq E.coordinates]; intros; split; field_simplify_eq;
62 repeat split; eauto using E.denominator_nonzero_x; eauto using E.denominator_nonzero_y; try fsatz.
63 - unshelve epose proof E.denominator_nonzero_x a2 _ _ d2 _ (x*r) y _ (x'*r) y' _; trivial; fsatz.
64 - unshelve epose proof E.denominator_nonzero_y a2 _ _ d2 _ (x*r) y _ (x'*r) y' _; trivial; fsatz.
65 - unshelve epose proof E.denominator_nonzero_x a1 _ _ d1 _ (x/r) y _ (x'/r) y' _; trivial; fsatz.
66 - unshelve epose proof E.denominator_nonzero_y a1 _ _ d1 _ (x/r) y _ (x'/r) y' _; trivial; fsatz.
67 Qed.
68 End __. End E.