@@ -24,7 +24,7 @@ Module Jacobian.
24
24
Local Infix "+" := Fadd. Local Infix "-" := Fsub.
25
25
Local Infix "*" := Fmul. Local Infix "/" := Fdiv.
26
26
Local Notation "x ^ 2" := (x*x). Local Notation "x ^ 3" := (x^2*x).
27
- Local Notation "2" := (1+1). Local Notation "4" := (2+2 ).
27
+ Local Notation "2" := (1+1). Local Notation "4" := (1+1+1+1 ).
28
28
Local Notation "8" := (4+4). Local Notation "27" := (4*4 + 4+4 +1+1+1).
29
29
Local Notation Wpoint := (@W.point F Feq Fadd Fmul a b).
30
30
Context {char_ge_12:@Ring.char_ge F Feq Fzero Fone Fopp Fadd Fsub Fmul 12%positive}
@@ -67,8 +67,8 @@ Module Jacobian.
67
67
| _ => progress destruct_head'_sum
68
68
| _ => progress destruct_head'_bool
69
69
| _ => progress destruct_head'_or
70
- | H: context[@dec ?P ?pf] |- _ => destruct (@dec P pf)
71
- | |- context[@dec ?P ?pf] => destruct (@dec P pf)
70
+ | H: context[@dec ?P ?pf] |- _ => destruct (@dec P pf) || destruct (@dec P pf) at 1
71
+ | |- context[@dec ?P ?pf] => destruct (@dec P pf) || destruct (@dec P pf) at 1
72
72
| |- ?P => lazymatch type of P with Prop => split end
73
73
end .
74
74
Ltac prept := repeat prept_step.
@@ -405,36 +405,57 @@ Module Jacobian.
405
405
end ;
406
406
fsatz ].
407
407
408
- Hint Unfold Jacobian.double negb andb : points_as_coordinates.
409
- Hint Unfold W.eq W.add Jacobian.to_affine Jacobian.of_affine Jacobian.add Jacobian.add_impl Jacobian.opp : points_as_coordinates.
410
-
411
- (* These could go into Jacobian.v *)
412
- Global Instance Proper_opp : Proper (eq ==> eq) opp. Proof . faster_t_noclear. Qed .
408
+ Local Hint Unfold W.add W.add' W.zero W.opp : points_as_coordinates.
409
+ Local Hint Unfold Jacobian.double Jacobian.double_impl negb andb : points_as_coordinates.
410
+ Local Hint Unfold Jacobian.to_affine Jacobian.to_affine_impl Jacobian.of_affine Jacobian.of_affine_impl Jacobian.add Jacobian.add_impl Jacobian.opp : points_as_coordinates.
413
411
414
412
Lemma of_affine_add P Q
415
413
: eq (of_affine (W.add P Q)) (add (of_affine P) (of_affine Q)).
416
- Proof . t. Qed .
417
-
418
- Lemma add_opp (P : point) :
419
- z_of (add P (opp P)) = 0.
420
- Proof . faster_t_noclear. Qed .
414
+ Proof . rewrite Jacobian.eq_iff, Jacobian.to_affine_add, 3Jacobian.to_affine_of_affine; reflexivity. Qed .
421
415
422
416
Lemma add_comm (P Q : point) :
423
417
eq (add P Q) (add Q P).
424
- Proof . faster_t_noclear. Qed .
418
+ Proof .
419
+ pose proof W.commutative_group(discriminant_nonzero:=discriminant_nonzero) _.
420
+ rewrite Jacobian.eq_iff, 2Jacobian.to_affine_add.
421
+ rewrite Hierarchy.commutative. reflexivity.
422
+ Qed .
425
423
426
424
Lemma add_zero_l (P Q : point) (H : z_of P = 0) :
427
425
eq (add P Q) Q.
428
- Proof . faster_t. Qed .
426
+ Proof .
427
+ pose proof W.commutative_group(discriminant_nonzero:=discriminant_nonzero) _.
428
+ rewrite Jacobian.eq_iff, Jacobian.to_affine_add.
429
+ rewrite (proj1 (Jacobian.iszero_iff P)), Hierarchy.left_identity; [reflexivity|].
430
+ case P as [ [ []?] ?]; cbv [Jacobian.iszero z_of proj1_sig snd] in *; trivial.
431
+ Qed .
429
432
430
433
Lemma add_zero_r (P Q : point) (H : z_of Q = 0) :
431
434
eq (add P Q) P.
432
- Proof . faster_t . Qed .
435
+ Proof . rewrite add_comm, add_zero_l; trivial; reflexivity . Qed .
433
436
434
437
Lemma add_double (P Q : point) :
435
438
eq P Q ->
436
439
eq (add P Q) (double P).
437
- Proof . faster_t_noclear. Qed .
440
+ Proof .
441
+ rewrite 2Jacobian.eq_iff, Jacobian.to_affine_add, Jacobian.to_affine_double.
442
+ intros ->; reflexivity.
443
+ Qed .
444
+
445
+ Lemma add_opp_same_r (P : point) :
446
+ eq (add P (opp P)) (of_affine W.zero).
447
+ Proof .
448
+ pose proof W.commutative_group(discriminant_nonzero:=discriminant_nonzero) _.
449
+ rewrite Jacobian.eq_iff, Jacobian.to_affine_add, Jacobian.to_affine_of_affine, Jacobian.to_affine_opp.
450
+ rewrite Hierarchy.right_inverse. reflexivity.
451
+ Qed .
452
+
453
+ Lemma z_of_eq_zero (P : point) : eq P (of_affine W.zero) -> z_of P = 0.
454
+ Proof . prept. match goal with H : 0 <> 0 |- _ => case (H ltac:(reflexivity)) end. Qed .
455
+
456
+ Lemma z_of_add_opp_same_r (P : point) :
457
+ z_of (add P (opp P)) = 0.
458
+ Proof . apply z_of_eq_zero, add_opp_same_r. Qed .
438
459
439
460
(* This uses assumptions not present in Jacobian.v,
440
461
namely char_ge_12 and discriminant_nonzero. *)
@@ -465,7 +486,7 @@ Module Jacobian.
465
486
466
487
Lemma opp_co_z (P : point) :
467
488
co_z P (opp P).
468
- Proof . unfold co_z; faster_t . Qed .
489
+ Proof . unfold co_z. prept . Qed .
469
490
470
491
Program Definition make_co_z (P Q : point) (HQaff : z_of Q = 1) : point*point :=
471
492
match proj1_sig P, proj1_sig Q return (F*F*F)*(F*F*F) with
@@ -479,8 +500,8 @@ Module Jacobian.
479
500
let t2 := t3 * t2 in
480
501
(P, (t1, t2, t3))
481
502
end .
482
- Next Obligation . Proof . faster_t . Qed .
483
- Next Obligation . Proof . faster_t. Qed .
503
+ Next Obligation . Proof . prept . Qed .
504
+ Next Obligation . Proof . prept. par: faster_t. Qed .
484
505
485
506
Hint Unfold is_point co_z make_co_z : points_as_coordinates.
486
507
@@ -520,17 +541,17 @@ Module Jacobian.
520
541
let t5 := t5 - t2 in
521
542
((t4, t5, t3), (t1, t2, t3))
522
543
end .
523
- Next Obligation . Proof . faster_t_noclear. Qed .
524
- Next Obligation . Proof . faster_t. Qed .
544
+ Next Obligation . Proof . prept. all : faster_t_noclear. Qed .
545
+ Next Obligation . Proof . prept. all : faster_t. Qed .
525
546
526
- Hint Unfold zaddu : points_as_coordinates.
547
+ Hint Unfold zaddu Jacobian.add_nz_nz : points_as_coordinates.
527
548
528
549
(* ZADDU(P, Q) = (P + Q, P) if P <> Q, Q <> -P *)
529
550
Lemma zaddu_correct (P Q : point) (H : co_z P Q)
530
551
(Hneq : x_of P <> x_of Q):
531
552
let '(R1, R2) := zaddu P Q H in
532
553
eq (add P Q) R1 /\ eq P R2 /\ co_z R1 R2.
533
- Proof . faster_t_noclear. Qed .
554
+ Proof . prept. par : faster_t_noclear. Qed .
534
555
535
556
Lemma zaddu_correct_alt (P Q : point) (H : co_z P Q) :
536
557
let '(R1, R2) := zaddu P Q H in
@@ -546,7 +567,7 @@ Module Jacobian.
546
567
Lemma zaddu_correct0 (P : point) :
547
568
let '(R1, R2) := zaddu P (opp P) (opp_co_z P) in
548
569
z_of R1 = 0 /\ co_z R1 R2.
549
- Proof . faster_t_noclear. Qed .
570
+ Proof . prept. all : faster_t_noclear. Qed .
550
571
551
572
(* Scalar Multiplication on Weierstraß Elliptic Curves from Co-Z Arithmetic *)
552
573
(* Goundar, Joye, Miyaji, Rivain, Vanelli *)
@@ -587,16 +608,16 @@ Module Jacobian.
587
608
let t2 := t2 + t6 in
588
609
((t1, t2, t3), (t4, t5, t3))
589
610
end .
590
- Next Obligation . Proof . faster_t_noclear. Qed .
591
- Next Obligation . Proof . faster_t_noclear. Qed .
611
+ Next Obligation . Proof . prept. all : faster_t_noclear. Qed .
612
+ Next Obligation . Proof . prept. all : faster_t_noclear. Qed .
592
613
593
614
Hint Unfold zaddc : points_as_coordinates.
594
615
(* ZADDC(P, Q) = (P + Q, P - Q) if P <> Q, Q <> -P *)
595
616
Lemma zaddc_correct (P Q : point) (H : co_z P Q)
596
617
(Hneq : x_of P <> x_of Q):
597
618
let '(R1, R2) := zaddc P Q H in
598
619
eq (add P Q) R1 /\ eq (add P (opp Q)) R2 /\ co_z R1 R2.
599
- Proof . faster_t_noclear. Qed .
620
+ Proof . prept. par : faster_t_noclear. Qed .
600
621
601
622
Lemma zaddc_correct_alt (P Q : point) (H : co_z P Q) :
602
623
let '(R1, R2) := zaddc P Q H in
@@ -735,7 +756,7 @@ Module Jacobian.
735
756
rewrite add_assoc, add_comm. reflexivity.
736
757
- rewrite <- A2, <- B1, <- B2.
737
758
rewrite (add_comm P Q).
738
- rewrite add_assoc. rewrite add_zero_r; [reflexivity|apply add_opp ].
759
+ rewrite add_assoc. rewrite add_zero_r; [reflexivity|apply z_of_add_opp_same_r ].
739
760
Qed .
740
761
741
762
Lemma zdau_naive_correct_alt (P Q : point) (H : co_z P Q)
@@ -756,7 +777,7 @@ Module Jacobian.
756
777
rewrite add_assoc, add_comm. reflexivity.
757
778
- rewrite <- A2, <- B1, <- B2.
758
779
rewrite (add_comm P Q).
759
- rewrite add_assoc. rewrite add_zero_r; [reflexivity|apply add_opp ].
780
+ rewrite add_assoc. rewrite add_zero_r; [reflexivity|apply z_of_add_opp_same_r ].
760
781
Qed .
761
782
762
783
(* Scalar Multiplication on Weierstraß Elliptic Curves from Co-Z Arithmetic *)
@@ -816,16 +837,16 @@ Module Jacobian.
816
837
let t5 := t7 - t5 in
817
838
((t1, t2, t3), (t4, t5, t3))
818
839
end .
819
- Next Obligation . Proof . faster_t_noclear. Qed .
820
- Next Obligation . Proof . faster_t_noclear. Qed .
840
+ Next Obligation . Proof . prept. par:setoid_subst_rel Feq; faster_t_noclear. Qed .
841
+ Next Obligation . Proof . prept. par: faster_t_noclear. Qed .
821
842
822
843
Hint Unfold zdau : points_as_coordinates.
823
844
824
845
Lemma zdau_naive_eq_zdau (P Q : point) (H : co_z P Q) :
825
846
let '(R1, R2) := zdau_naive P Q H in
826
847
let '(S1, S2) := zdau P Q H in
827
848
eq R1 S1 /\ eq R2 S2.
828
- Proof . faster_t. all: try fsatz. Qed .
849
+ Proof . prept. par : faster_t; try fsatz. Qed .
829
850
830
851
(* Direct proof is intensive, which is why we need the naive implementation *)
831
852
Lemma zdau_correct (P Q : point) (H : co_z P Q)
0 commit comments