From 40750bf32318eb8d93e9537083e4288e55b2555e Mon Sep 17 00:00:00 2001 From: Andres Erbsen Date: Sat, 16 Jan 2016 19:39:26 -0500 Subject: PointFOrmats,EdDSA: remove redundant axioms --- src/Curves/Curve25519.v | 68 ----------------------------------------------- src/Curves/PointFormats.v | 31 ++++++++++----------- 2 files changed, 16 insertions(+), 83 deletions(-) delete mode 100644 src/Curves/Curve25519.v (limited to 'src/Curves') diff --git a/src/Curves/Curve25519.v b/src/Curves/Curve25519.v deleted file mode 100644 index 248e0af6e..000000000 --- a/src/Curves/Curve25519.v +++ /dev/null @@ -1,68 +0,0 @@ -Require Import Zpower ZArith Znumtheory. -Require Import Crypto.Galois.GaloisField. -Require Import Crypto.Curves.PointFormats. - -Definition two_255_19 := 2^255 - 19. (* *) -Fact two_255_19_prime : prime two_255_19. Admitted. -Module Modulus25519 <: Modulus. - Definition modulus := exist _ two_255_19 two_255_19_prime. -End Modulus25519. - -Module Curve25519Params <: TwistedEdwardsParams Modulus25519 <: Minus1Params Modulus25519. - Module Import GFDefs := GaloisField Modulus25519. - - Local Open Scope GF_scope. - - Definition a : GF := -1. - Definition d : GF := -121665 / 121666. - - Lemma a_nonzero : a <> 0. - Proof. - discriminate. - Qed. - - Definition sqrt_a: GF := 19681161376707505956807079304988542015446066515923890162744021073123829784752. - - Lemma a_square : sqrt_a^2 = a. - Proof. - (* An example of how to use ring properly *) - replace (sqrt_a ^ 2) with (sqrt_a * sqrt_a) by ring. - assert ((inject ((GFToZ sqrt_a) * (GFToZ sqrt_a)))%Z = a). - - - apply gf_eq. - (* vm_compute runs out of memory. *) - admit. - - - rewrite inject_distr_mul in H. - intuition. - - Admitted. - - Lemma d_nonsquare : forall x, x * x <> d. - (* *) - Admitted. - - Definition A : GF := 486662. - (* Definition montgomeryOnCurve25519 := montgomeryOnCurve 1 A. *) - - (* Module-izing Twisted was a breaking change - Definition m1TwistedOnCurve25519 := twistedOnCurve (0 -1) d. - - Definition identityTwisted : twisted := mkTwisted 0 1. - - Lemma identityTwistedOnCurve : m1TwistedOnCurve25519 identityTwisted. - unfold m1TwistedOnCurve25519, twistedOnCurve. - simpl; field. - Qed. - - *) - - Definition basepointY := 4 / 5. - - (* True iff this prime is odd *) - Definition char_gt_2: (1+1) <> 0. - Admitted. -End Curve25519Params. - -Module Edwards25519 := CompleteTwistedEdwardsCurve Modulus25519 Curve25519Params. -Module Edwards25519Minus1Twisted := Minus1Format Modulus25519 Curve25519Params. diff --git a/src/Curves/PointFormats.v b/src/Curves/PointFormats.v index a44ed7a6d..85f69b87a 100644 --- a/src/Curves/PointFormats.v +++ b/src/Curves/PointFormats.v @@ -5,12 +5,11 @@ Require Import BinNums NArith Nnat ZArith. Module Type TwistedEdwardsParams (M : Modulus). Module Export GFDefs := GaloisField M. + Axiom modulus_odd : (primeToZ M.modulus > 2)%Z. Local Open Scope GF_scope. - Axiom char_gt_2 : (1+1) <> 0. Parameter a : GF. Axiom a_nonzero : a <> 0. - Parameter sqrt_a : GF. - Axiom a_square : sqrt_a^2 = a. + Axiom a_square : exists sqrt_a, sqrt_a^2 = a. Parameter d : GF. Axiom d_nonsquare : forall x, x * x <> d. End TwistedEdwardsParams. @@ -232,6 +231,12 @@ Module CompleteTwistedEdwardsCurve (M : Modulus) (Import P : TwistedEdwardsParam Qed. + Lemma char_gt_2 : inject 2 <> 0. + intro H; inversion H; clear H. + pose proof modulus_odd. + rewrite Zmod_small in H1; intuition; auto; omega. + Qed. + Ltac whatsNotZero := repeat match goal with | [H: ?lhs = ?rhs |- _ ] => @@ -266,7 +271,7 @@ Module CompleteTwistedEdwardsCurve (M : Modulus) (Import P : TwistedEdwardsParam pose proof char_gt_2. pose proof a_nonzero as Ha_nonzero. destruct a_square as [sqrt_a a_square]. - rewrite a_square in Ha_nonzero. + rewrite <-a_square in *. (* Furthermore... *) pose proof (eq_refl (d*x1^2*y1^2*(sqrt_a^2*x2^2 + y2^2))) as Heqt. @@ -296,16 +301,12 @@ Module CompleteTwistedEdwardsCurve (M : Modulus) (Import P : TwistedEdwardsParam assert (Hc: (sqrt_a * x2 + y2) + (sqrt_a * x2 - y2) = 0) by (repeat rewriteAny; field). - rewrite a_square in *. replace (sqrt_a * x2 + y2 + (sqrt_a * x2 - y2)) with (inject 2 * sqrt_a * x2) in Hc by field. (* contradiction: product of nonzero things is zero *) - destruct (mul_zero_why _ _ Hc) as [Hcc|Hcc]; try solve [subst; intuition]. - destruct (mul_zero_why _ _ Hcc) as [Hccc|Hccc]; subst; intuition; apply Ha_nonzero. - - + replace (inject 2%Z) with (1+1) in Hccc by field; intuition. - - + rewrite <- a_square; simpl; rewrite Hccc; field. + destruct (mul_zero_why _ _ Hc) as [Hcc|Hcc]; subst; intuition. + destruct (mul_zero_why _ _ Hcc) as [Hccc|Hccc]; subst; intuition. + apply Ha_nonzero; field. Qed. Lemma edwardsAddCompletePlus x1 y1 x2 y2 : onCurve (x1,y1) -> @@ -604,12 +605,12 @@ End CompleteTwistedEdwardsFacts. Module Type Minus1Params (Import M : Modulus) <: TwistedEdwardsParams M. Module Export GFDefs := GaloisField M. + Axiom modulus_odd : (primeToZ M.modulus > 2)%Z. Local Open Scope GF_scope. - Axiom char_gt_2 : (1+1) <> 0. + Axiom char_gt_2 : inject 2 <> 0. Definition a := inject (- 1). Axiom a_nonzero : a <> 0. - Parameter sqrt_a : GF. - Axiom a_square : sqrt_a^2 = a. + Axiom a_square : exists sqrt_a, sqrt_a^2 = a. Parameter d : GF. Axiom d_nonsquare : forall x, x * x <> d. End Minus1Params. @@ -680,7 +681,7 @@ Module ExtendedM1 (M : Modulus) (Import P : Minus1Params M) <: CompleteTwistedEd extended_tac. Qed. - Local Notation "2" := (1+1). + Local Notation "2" := (inject 2). (** Second equation from section 3.1, also and *) Definition unifiedAdd (P1 P2 : point) : point := let '(X1, Y1, Z1, T1) := P1 in -- cgit v1.2.3