diff options
author | 2017-06-19 15:44:30 -0400 | |
---|---|---|
committer | 2017-06-19 15:44:30 -0400 | |
commit | d4e374da36d87a502a61456abfe4b2eec25023b7 (patch) | |
tree | 7dd3dd25d893e6f0144949aacd402640194b041a /src/Specific/MontgomeryP256_128.v | |
parent | e11bdc16ba8d0d3b92719bb9cef304a7ba52158d (diff) |
Improve mulmod_256 specs
Now they talk about F. Pair-programmed with Andres.
Diffstat (limited to 'src/Specific/MontgomeryP256_128.v')
-rw-r--r-- | src/Specific/MontgomeryP256_128.v | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/Specific/MontgomeryP256_128.v b/src/Specific/MontgomeryP256_128.v index 9f3fb7f52..71df829e6 100644 --- a/src/Specific/MontgomeryP256_128.v +++ b/src/Specific/MontgomeryP256_128.v @@ -97,7 +97,7 @@ Z.of_nat *) reflexivity. Defined. -Definition mulmod_256 : { f:Tuple.tuple Z sz -> Tuple.tuple Z sz -> Tuple.tuple Z sz +Definition mulmod_256'' : { f:Tuple.tuple Z sz -> Tuple.tuple Z sz -> Tuple.tuple Z sz | forall (A B : Tuple.tuple Z sz), Saturated.small (Z.pos r) A -> Saturated.small (Z.pos r) B -> let eval := Saturated.eval (Z.pos r) in @@ -124,5 +124,44 @@ Proof. end ). Defined. +Import ModularArithmetic. + +(*Definition mulmod_256 : { f:Tuple.tuple Z sz -> Tuple.tuple Z sz -> Tuple.tuple Z sz + | forall (A : Tuple.tuple Z sz) (_ : Saturated.small (Z.pos r) A) + (B : Tuple.tuple Z sz) (_ : Saturated.small (Z.pos r) B), + Saturated.small (Z.pos r) (f A B) + /\ (let eval := Saturated.eval (Z.pos r) in + 0 <= eval (f A B) < Z.pos r^Z.of_nat sz + /\ (eval (f A B) mod Z.pos m + = (eval A * eval B * r'^(Z.of_nat sz)) mod Z.pos m))%Z + }. +Proof.*) + +(** TODO: MOVE ME *) +Definition montgomery_to_F (v : Z) : F m + := (F.of_Z m v * F.of_Z m (r'^Z.of_nat sz)%Z)%F. + +Definition mulmod_256 : { f:Tuple.tuple Z sz -> Tuple.tuple Z sz -> Tuple.tuple Z sz + | forall (A : Tuple.tuple Z sz) (_ : Saturated.small (Z.pos r) A) + (B : Tuple.tuple Z sz) (_ : Saturated.small (Z.pos r) B), + Saturated.small (Z.pos r) (f A B) + /\ (let eval := Saturated.eval (Z.pos r) in + montgomery_to_F (eval (f A B)) + = (montgomery_to_F (eval A) * montgomery_to_F (eval B))%F) }. +Proof. + exists (proj1_sig mulmod_256''). + abstract ( + intros A Asm B Bsm; + pose proof (proj2_sig mulmod_256'' A B Asm Bsm) as H; + cbv zeta in *; + split; try solve [ destruct_head'_and; assumption ]; + rewrite ModularArithmeticTheorems.F.eq_of_Z_iff in H; + unfold montgomery_to_F; + destruct H as [H1 [H2 H3]]; + rewrite H3; + rewrite <- !ModularArithmeticTheorems.F.of_Z_mul; + f_equal; nia + ). +Defined. Print Assumptions mulmod_256. |