| 1 |
From Coq Require Import BinPosDef. |
| 2 |
Require Import Crypto.Algebra.Field. |
| 3 |
Require Import Crypto.Util.GlobalSettings. |
| 4 |
Require Import Crypto.Util.Sum Crypto.Util.Prod. |
| 5 |
Require Import Crypto.Util.Tactics.BreakMatch. |
| 6 |
Require Import Crypto.Util.Decidable. |
| 7 |
Require Import Crypto.Spec.MontgomeryCurve Crypto.Curves.Montgomery.Affine. |
| 8 |
Require Import Crypto.Spec.WeierstrassCurve Crypto.Curves.Weierstrass.Affine. |
| 9 |
Require Import Crypto.Curves.Weierstrass.AffineProofs. |
| 10 |
|
| 11 |
Module M. |
| 12 |
Section MontgomeryCurve. |
| 13 |
Import BinNat. |
| 14 |
Context {F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv} |
| 15 |
{field:@Algebra.Hierarchy.field F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv} |
| 16 |
{Feq_dec:Decidable.DecidableRel Feq}. |
| 17 |
|
| 18 |
Local Infix "=" := Feq : type_scope. Local Notation "a <> b" := (not (a = b)) : type_scope. |
| 19 |
Local Infix "+" := Fadd. Local Infix "*" := Fmul. |
| 20 |
Local Infix "-" := Fsub. Local Infix "/" := Fdiv. |
| 21 |
Local Notation "- x" := (Fopp x). |
| 22 |
Local Notation "x ^ 2" := (x*x) (at level 30). |
| 23 |
Local Notation "x ^ 3" := (x*x^2) (at level 30). |
| 24 |
Local Notation "0" := Fzero. |
| 25 |
Local Notation "1" := Fone. |
| 26 |
Local Notation "2" := (1+1). |
| 27 |
Local Notation "3" := (1+2). |
| 28 |
Local Notation "4" := (1+1+1+1). |
| 29 |
Local Notation "9" := (3*3). |
| 30 |
Local Notation "27" := (4*4 + 4+4 +1+1+1). |
| 31 |
Local Notation "'∞'" := unit : type_scope. |
| 32 |
Local Notation "'∞'" := (inr tt) : core_scope. |
| 33 |
Local Notation "( x , y )" := (inl (pair x y)). |
| 34 |
Local Open Scope core_scope. |
| 35 |
|
| 36 |
Context {a b: F} |
| 37 |
{aw bw} |
| 38 |
{Haw : aw = (3-a^2)/(3*b^2)} |
| 39 |
{Hbw : bw = (2*a^3-9*a)/(27*b^3)}. |
| 40 |
|
| 41 |
Ltac t := |
| 42 |
repeat |
| 43 |
match goal with |
| 44 |
| _ => solve [ trivial ] |
| 45 |
| _ => progress intros |
| 46 |
| _ => progress subst |
| 47 |
| _ => progress Tactics.DestructHead.destruct_head' @M.point |
| 48 |
| _ => progress Tactics.DestructHead.destruct_head' @prod |
| 49 |
| _ => progress Tactics.DestructHead.destruct_head' @sum |
| 50 |
| _ => progress Tactics.DestructHead.destruct_head' @and |
| 51 |
| _ => progress Sum.inversion_sum |
| 52 |
| _ => progress Prod.inversion_prod |
| 53 |
| _ => progress Tactics.BreakMatch.break_match_hyps |
| 54 |
| _ => progress Tactics.BreakMatch.break_match |
| 55 |
| _ => progress cbv [M.coordinates M.add M.zero M.eq M.opp proj1_sig |
| 56 |
W.coordinates W.add W.zero W.eq W.opp |
| 57 |
M.of_Weierstrass M.to_Weierstrass] in * |
| 58 |
| |- _ /\ _ => split | |- _ <-> _ => split |
| 59 |
end. |
| 60 |
|
| 61 |
Global Instance MontgomeryWeierstrassIsomorphism {_1 _2 _3 _4 _5 _6 _7} |
| 62 |
{discriminant_nonzero:id(4*aw*aw*aw + 27*bw*bw <> 0)} |
| 63 |
{char_ge_12:@Ring.char_ge F Feq Fzero Fone Fopp Fadd Fsub Fmul 12} |
| 64 |
{char_ge_28:@Ring.char_ge F Feq Fzero Fone Fopp Fadd Fsub Fmul 28} (* XXX: this is a workaround for nsatz assuming arbitrary characteristic *) |
| 65 |
: |
| 66 |
@Group.isomorphic_commutative_groups |
| 67 |
(@W.point F Feq Fadd Fmul aw bw) |
| 68 |
W.eq |
| 69 |
(@W.add F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv field _1 _2 aw bw) |
| 70 |
W.zero |
| 71 |
(@W.opp F Feq Fzero Fone Fopp Fadd Fsub Fmul Finv Fdiv aw bw field _1) |
| 72 |
|
| 73 |
(@M.point F Feq Fadd Fmul a b) |
| 74 |
M.eq |
| 75 |
(M.add(char_ge_3:=_3)(b_nonzero:=_4)) |
| 76 |
M.zero |
| 77 |
(M.opp(b_nonzero:=_7)) |
| 78 |
|
| 79 |
(M.of_Weierstrass(Haw:=Haw)(Hbw:=Hbw)(b_nonzero:=_5)) |
| 80 |
(M.to_Weierstrass(Haw:=Haw)(Hbw:=Hbw)(b_nonzero:=_6)). |
| 81 |
Proof. |
| 82 |
eapply Group.commutative_group_by_isomorphism. |
| 83 |
{ eapply W.commutative_group; trivial. } |
| 84 |
Time all:t. |
| 85 |
Time par: abstract fsatz. |
| 86 |
Qed. |
| 87 |
|
| 88 |
End MontgomeryCurve. |
| 89 |
End M. |