-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instantiate Edwards-Montgomery isomorphism for Curve25519
- Loading branch information
1 parent
1452648
commit e68e0f0
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Require Import Coq.ZArith.ZArith. Local Open Scope Z_scope. | ||
Require Import Crypto.Spec.ModularArithmetic. Local Open Scope F_scope. | ||
Require Import Crypto.Curves.EdwardsMontgomery. Import M. | ||
Require Import Crypto.Curves.Edwards.TwistIsomorphism. | ||
Require Import Crypto.Spec.Curve25519. | ||
|
||
Local Definition sqrtm1 : F p := F.pow (F.of_Z _ 2) ((N.pos p-1)/4). | ||
Local Definition sqrt := PrimeFieldTheorems.F.sqrt_5mod8 sqrtm1. | ||
|
||
Import MontgomeryCurve CompleteEdwardsCurve. | ||
|
||
Local Definition a' := (M.a + (1 + 1)) / M.b. | ||
Local Definition d' := (M.a - (1 + 1)) / M.b. | ||
Definition r := sqrt (F.inv ((a' / M.b) / E.a)). | ||
|
||
Local Lemma is_twist : E.a * d' = a' * E.d. Proof. Decidable.vm_decide. Qed. | ||
Local Lemma nonzero_a' : a' <> 0. Proof. Decidable.vm_decide. Qed. | ||
Local Lemma r_correct : E.a = r * r * a'. Proof. Decidable.vm_decide. Qed. | ||
|
||
Definition Montgomery_of_Edwards (P : Curve25519.E.point) : Curve25519.M.point := | ||
@of_Edwards _ _ _ _ _ _ _ _ _ _ field _ char_ge_3 M.a M.b M.b_nonzero a' d' eq_refl eq_refl nonzero_a' | ||
(@E.point2_of_point1 _ _ _ _ _ _ _ _ _ _ field _ E.a E.d a' d' is_twist E.nonzero_a nonzero_a' r r_correct P). | ||
|
||
Definition Edwards_of_Montgomery (P : Curve25519.M.point) : Curve25519.E.point := | ||
@E.point1_of_point2 _ _ _ _ _ _ _ _ _ _ field _ E.a E.d a' d' is_twist E.nonzero_a nonzero_a' r r_correct | ||
(@to_Edwards _ _ _ _ _ _ _ _ _ _ field _ M.a M.b M.b_nonzero a' d' eq_refl eq_refl nonzero_a' P). | ||
|
||
Local Notation Eopp := ((@AffineProofs.E.opp _ _ _ _ _ _ _ _ _ _ field _ E.a E.d E.nonzero_a)). | ||
|
||
Local Arguments Hierarchy.commutative_group _ {_} _ {_ _}. | ||
Local Arguments CompleteEdwardsCurve.E.add {_ _ _ _ _ _ _ _ _ _ _ _ _} _ _ {_ _ _}. | ||
Local Arguments Monoid.is_homomorphism {_ _ _ _ _ _}. | ||
Local Arguments to_Edwards {_ _ _ _ _ _ _ _ _ _ _ _ _ _ _} _ _ { _ _ _ }. | ||
Local Arguments of_Edwards {_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _} _ _ { _ _ _ }. | ||
|
||
Lemma EdwardsMontgomery25519 : @Group.isomorphic_commutative_groups | ||
Curve25519.E.point E.eq Curve25519.E.add Curve25519.E.zero Eopp Curve25519.M.point | ||
M.eq Curve25519.M.add M.zero Curve25519.M.opp | ||
Montgomery_of_Edwards Edwards_of_Montgomery. | ||
Proof. | ||
cbv [Montgomery_of_Edwards Edwards_of_Montgomery]. | ||
epose proof E.twist_isomorphism(a1:=E.a)(a2:=a')(d1:=E.d)(d2:=d')(r:=r) as AB. | ||
epose proof EdwardsMontgomeryIsomorphism(a:=Curve25519.M.a)(b:=Curve25519.M.b)as BC. | ||
destruct AB as [A B ab ba], BC as [_ C bc cb]. | ||
pose proof Group.compose_homomorphism(homom:=ab)(homom2:=bc) as ac. | ||
pose proof Group.compose_homomorphism(homom:=cb)(homom2:=ba)(groupH2:=ltac:(eapply A)) as ca. | ||
split; try exact ac; try exact ca; try exact A; try exact C. | ||
Unshelve. | ||
all : try (pose (@PrimeFieldTheorems.F.Decidable_square p prime_p eq_refl); Decidable.vm_decide). | ||
all : try (eapply Hierarchy.char_ge_weaken; try apply ModularArithmeticTheorems.F.char_gt; Decidable.vm_decide). | ||
Qed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters