1
1
Require Import Coq.ZArith.ZArith. Local Open Scope Z_scope.
2
+ Require Import Crypto.Util.Decidable.
2
3
Require Import Crypto.Spec.ModularArithmetic. Local Open Scope F_scope.
3
4
Require Import Crypto.Curves.EdwardsMontgomery. Import M.
4
5
Require Import Crypto.Curves.Edwards.TwistIsomorphism.
@@ -11,19 +12,26 @@ Import MontgomeryCurve CompleteEdwardsCurve.
11
12
12
13
Local Definition a' := (M.a + (1 + 1)) / M.b.
13
14
Local Definition d' := (M.a - (1 + 1)) / M.b.
14
- Definition r := sqrt (F.inv ((a' / M.b) / E.a)).
15
+ Local Definition r := sqrt (F.inv ((a' / M.b) / E.a)).
15
16
16
- Local Lemma is_twist : E.a * d' = a' * E.d. Proof . Decidable. vm_decide. Qed .
17
- Local Lemma nonzero_a' : a' <> 0. Proof . Decidable. vm_decide. Qed .
18
- Local Lemma r_correct : E.a = r * r * a'. Proof . Decidable. vm_decide. Qed .
17
+ Local Lemma is_twist : E.a * d' = a' * E.d. Proof . vm_decide. Qed .
18
+ Local Lemma nonzero_a' : a' <> 0. Proof . vm_decide. Qed .
19
+ Local Lemma r_correct : E.a = r * r * a'. Proof . vm_decide. Qed .
19
20
20
- Definition Montgomery_of_Edwards (P : Curve25519.E.point) : Curve25519.M.point :=
21
- @of_Edwards _ _ _ _ _ _ _ _ _ _ field _ char_ge_3 M.a M.b M.b_nonzero a' d' eq_refl eq_refl nonzero_a'
22
- (@E.point2_of_point1 _ _ _ _ _ _ _ _ _ _ field _ E.a E.d a' d' is_twist E.nonzero_a nonzero_a' r r_correct P).
23
-
24
- Definition Edwards_of_Montgomery (P : Curve25519.M.point) : Curve25519.E.point :=
21
+ Module E.
22
+ Definition of_Montgomery (P : Curve25519.M.point) : Curve25519.E.point :=
25
23
@E.point1_of_point2 _ _ _ _ _ _ _ _ _ _ field _ E.a E.d a' d' is_twist E.nonzero_a nonzero_a' r r_correct
26
24
(@to_Edwards _ _ _ _ _ _ _ _ _ _ field _ M.a M.b M.b_nonzero a' d' eq_refl eq_refl nonzero_a' P).
25
+ Lemma of_Montgomery_B : E.eq E.B (of_Montgomery M.B). Proof . vm_decide. Qed .
26
+ End E.
27
+
28
+ Module M.
29
+ Definition of_Edwards (P : Curve25519.E.point) : Curve25519.M.point :=
30
+ @of_Edwards _ _ _ _ _ _ _ _ _ _ field _ char_ge_3 M.a M.b M.b_nonzero a' d' eq_refl eq_refl nonzero_a'
31
+ (@E.point2_of_point1 _ _ _ _ _ _ _ _ _ _ field _ E.a E.d a' d' is_twist E.nonzero_a nonzero_a' r r_correct P).
32
+ Lemma of_Edwards_B : M.eq M.B (of_Edwards E.B). Proof .
33
+ Proof. simple notypeclasses refine (@dec_bool _ _ _). apply Affine.M.Decidable_eq. vm_decide. Qed .
34
+ End M.
27
35
28
36
Local Notation Eopp := ((@AffineProofs.E.opp _ _ _ _ _ _ _ _ _ _ field _ E.a E.d E.nonzero_a)).
29
37
@@ -36,16 +44,16 @@ Local Arguments of_Edwards {_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _} _ _ { _ _ _ }.
36
44
Lemma EdwardsMontgomery25519 : @Group.isomorphic_commutative_groups
37
45
Curve25519.E.point E.eq Curve25519.E.add Curve25519.E.zero Eopp Curve25519.M.point
38
46
M.eq Curve25519.M.add M.zero Curve25519.M.opp
39
- Montgomery_of_Edwards Edwards_of_Montgomery .
47
+ M.of_Edwards E.of_Montgomery .
40
48
Proof .
41
- cbv [Montgomery_of_Edwards Edwards_of_Montgomery ].
49
+ cbv [M.of_Edwards E.of_Montgomery ].
42
50
epose proof E.twist_isomorphism(a1:=E.a)(a2:=a')(d1:=E.d)(d2:=d')(r:=r) as AB.
43
51
epose proof EdwardsMontgomeryIsomorphism(a:=Curve25519.M.a)(b:=Curve25519.M.b)as BC.
44
52
destruct AB as [A B ab ba], BC as [_ C bc cb].
45
53
pose proof Group.compose_homomorphism(homom:=ab)(homom2:=bc) as ac.
46
54
pose proof Group.compose_homomorphism(homom:=cb)(homom2:=ba)(groupH2:=ltac:(eapply A)) as ca.
47
55
split; try exact ac; try exact ca; try exact A; try exact C.
48
56
Unshelve.
49
- all : try (pose (@PrimeFieldTheorems.F.Decidable_square p prime_p eq_refl); Decidable. vm_decide).
50
- all : try (eapply Hierarchy.char_ge_weaken; try apply ModularArithmeticTheorems.F.char_gt; Decidable. vm_decide).
57
+ all : try (pose (@PrimeFieldTheorems.F.Decidable_square p prime_p eq_refl); vm_decide).
58
+ all : try (eapply Hierarchy.char_ge_weaken; try apply ModularArithmeticTheorems.F.char_gt; vm_decide).
51
59
Qed .
0 commit comments