| 1 |
From Crypto.Bedrock.P256 Require Import Specs Platform Coord Jacobian. |
| 2 |
|
| 3 |
Import Specs.NotationsCustomEntry Specs.coord Specs.point. |
| 4 |
|
| 5 |
Import bedrock2.Syntax bedrock2.NotationsCustomEntry |
| 6 |
LittleEndianList |
| 7 |
ZArith.BinInt |
| 8 |
BinInt BinNat Init.Byte |
| 9 |
PrimeFieldTheorems ModInv |
| 10 |
micromega.Lia |
| 11 |
coqutil.Byte |
| 12 |
Lists.List micromega.Lia |
| 13 |
Jacobian |
| 14 |
Coq.Strings.String Coq.Lists.List |
| 15 |
ProgramLogic WeakestPrecondition |
| 16 |
ProgramLogic.Coercions |
| 17 |
Word.Interface OfListWord Separation SeparationLogic |
| 18 |
letexists |
| 19 |
BasicC64Semantics |
| 20 |
ListIndexNotations |
| 21 |
SepAutoArray |
| 22 |
symmetry |
| 23 |
PeanoNat micromega.Lia |
| 24 |
Tactics |
| 25 |
UniquePose |
| 26 |
micromega.Lia Word.Properties. |
| 27 |
|
| 28 |
Import ListIndexNotations. |
| 29 |
Local Open Scope list_index_scope. |
| 30 |
Local Open Scope Z_scope. |
| 31 |
Local Open Scope bool_scope. |
| 32 |
Local Open Scope string_scope. |
| 33 |
Local Open Scope list_scope. |
| 34 |
|
| 35 |
Local Notation "xs $@ a" := (map.of_list_word_at a xs) |
| 36 |
(at level 10, format "xs $@ a"). |
| 37 |
Local Notation "$ n" := (match word.of_Z n return word with w => w end) (at level 9, format "$ n"). |
| 38 |
Local Notation "p .+ n" := (word.add p (word.of_Z n)) (at level 50, format "p .+ n", left associativity). |
| 39 |
Local Coercion F.to_Z : F >-> Z. |
| 40 |
|
| 41 |
Import coqutil.Map.Interface. |
| 42 |
Import bedrock2.ToCString. |
| 43 |
Import Macros.WithBaseName. |
| 44 |
Import String List. Local Open Scope string_scope. Local Open Scope list_scope. |
| 45 |
|
| 46 |
|
| 47 |
Axiom p256_coord_sqr : Syntax.func. |
| 48 |
Axiom p256_coord_sqr_ok : forall functions, map.get functions "p256_coord_sqr" = Some p256_coord_sqr -> spec_of_p256_coord_sqr functions. |
| 49 |
|
| 50 |
Axiom p256_coord_mul : Syntax.func. |
| 51 |
Axiom p256_coord_mul_ok : forall functions, map.get functions "p256_coord_mul" = Some p256_coord_mul -> spec_of_p256_coord_mul functions. |
| 52 |
|
| 53 |
Import memcpy shrd full_sub full_add full_mul memmove. |
| 54 |
|
| 55 |
Definition platform := &[, |
| 56 |
full_add; full_sub; full_mul; shrd; |
| 57 |
br_value_barrier; br_declassify; br_broadcast_negative; br_broadcast_nonzero; br_broadcast_odd; br_cmov; br_memcxor |
| 58 |
]. |
| 59 |
|
| 60 |
Definition libc := &[, memmove; br_memcpy; br_memset]. |
| 61 |
|
| 62 |
Local Definition c_func f : string := "static inline "++ c_func f. |
| 63 |
|
| 64 |
Compute String.concat LF (List.map c_func platform). |
| 65 |
|
| 66 |
Definition jacobian := &[, |
| 67 |
br_broadcast_odd; |
| 68 |
p256_coord_halve; |
| 69 |
|
| 70 |
p256_point_iszero; |
| 71 |
p256_point_double; |
| 72 |
p256_point_add_nz_nz_neq; |
| 73 |
p256_point_add_vartime_if_doubling |
| 74 |
]. |
| 75 |
|
| 76 |
Compute String.concat LF (List.map c_func jacobian). |
| 77 |
|
| 78 |
(* |
| 79 |
p256_point_add_affine_nz_nz_neq; |
| 80 |
p256_point_add_affine_conditional |
| 81 |
|
| 82 |
sc_sub; |
| 83 |
sc_halve; |
| 84 |
fe_set_1; |
| 85 |
*) |
| 86 |
|
| 87 |
Definition asm := &[, p256_coord_sqr; p256_coord_mul |
| 88 |
]. |
| 89 |
|
| 90 |
Definition funcs := Eval cbv [List.app] in (jacobian ++ coord64 ++ asm ++ platform ++ libc)%list. |
| 91 |
|
| 92 |
Ltac pose_correctness lem := |
| 93 |
let funcs := match goal with |- _ (map.of_list ?funcs) => funcs end in |
| 94 |
let H := fresh in |
| 95 |
pose proof (lem (map.of_list funcs)) as H; |
| 96 |
unfold ProgramLogic.program_logic_goal_for in H; |
| 97 |
repeat lazymatch type of H with |
| 98 |
| map.get (map.of_list ?e) ?f = Some _ -> _ => specialize (H eq_refl) |
| 99 |
|| let t := type of H in fail 1 "function" f "not found in environment" e |
| 100 |
| ?P -> _ => match goal with HH : P |- _ => specialize (H HH) end |
| 101 |
|| let t := type of H in fail 1 "unsolved premises" t |
| 102 |
end. |
| 103 |
|
| 104 |
Local Existing Instance memmove.spec_of_memmove. |
| 105 |
#[export] Instance spec_of_memmove : spec_of "memmove". apply memmove.spec_of_memmove. Defined. |
| 106 |
|
| 107 |
Lemma link_jacobian : spec_of_p256_point_add_vartime_if_doubling (map.of_list funcs). |
| 108 |
Proof. |
| 109 |
pose_correctness full_add_ok. |
| 110 |
pose_correctness full_sub_ok. |
| 111 |
pose_correctness full_mul_ok. |
| 112 |
pose_correctness value_barrier_ok. |
| 113 |
pose_correctness br_declassify_ok. |
| 114 |
pose_correctness br_broadcast_negative_ok. |
| 115 |
pose_correctness br_broadcast_nonzero_ok. |
| 116 |
pose_correctness br_cmov_ok. |
| 117 |
pose_correctness br_broadcast_odd_ok. |
| 118 |
|
| 119 |
pose_correctness memmove.memmove_ok. |
| 120 |
match goal with H : _ |- _ => |
| 121 |
pose proof br_memcpy_ok (map.of_list funcs) eq_refl H end. |
| 122 |
pose_correctness br_memset_ok. |
| 123 |
pose_correctness br_memcxor_ok. |
| 124 |
|
| 125 |
pose_correctness shrd_ok. |
| 126 |
pose_correctness u256_shr_ok. |
| 127 |
pose_correctness u256_set_p256_minushalf_conditional_ok. |
| 128 |
|
| 129 |
pose_correctness p256_coord_add_ok. |
| 130 |
pose_correctness p256_coord_sub_nonmont_ok. |
| 131 |
pose_correctness p256_coord_sub_ok. |
| 132 |
pose_correctness fiat_coord_nonzero_ok. |
| 133 |
pose_correctness p256_coord_halve_ok. |
| 134 |
|
| 135 |
pose_correctness p256_coord_sqr_ok. |
| 136 |
pose_correctness p256_coord_mul_ok. |
| 137 |
|
| 138 |
pose_correctness p256_point_iszero_ok. |
| 139 |
pose_correctness p256_point_double_ok. |
| 140 |
|
| 141 |
pose_correctness p256_point_add_nz_nz_neq_ok. |
| 142 |
|
| 143 |
pose_correctness p256_point_add_vartime_if_doubling_ok. |
| 144 |
|
| 145 |
trivial. |
| 146 |
Qed. |
| 147 |
|
| 148 |
Print Assumptions link_jacobian. |