file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.qmont_mul_lemma
val qmont_mul_lemma: a:S.qelem -> b:S.qelem -> Lemma (S.qmul (from_qmont a) (from_qmont b) = from_qmont ((a * b * qmont_R_inv) % S.order))
val qmont_mul_lemma: a:S.qelem -> b:S.qelem -> Lemma (S.qmul (from_qmont a) (from_qmont b) = from_qmont ((a * b * qmont_R_inv) % S.order))
let qmont_mul_lemma a b = mont_mul_lemma_gen S.order qmont_R_inv a b
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 299, "start_col": 0, "start_line": 298 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //-------------------------- let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a let lemma_from_to_qmont_id a = mul_qmont_R_and_R_inv_is_one (); Math.Lemmas.swap_mul qmont_R qmont_R_inv; lemma_from_to_mont_id_gen S.order qmont_R qmont_R_inv a let qmont_add_lemma a b = mont_add_lemma_gen S.order qmont_R_inv a b
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.P256.PointOps.qelem -> b: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures Spec.P256.PointOps.qmul (Hacl.Spec.P256.Montgomery.from_qmont a) (Hacl.Spec.P256.Montgomery.from_qmont b) = Hacl.Spec.P256.Montgomery.from_qmont ((a * b) * Hacl.Spec.P256.Montgomery.qmont_R_inv % Spec.P256.PointOps.order))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Hacl.Spec.P256.Montgomery.mont_mul_lemma_gen", "Spec.P256.PointOps.order", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Prims.unit" ]
[]
true
false
true
false
false
let qmont_mul_lemma a b =
mont_mul_lemma_gen S.order qmont_R_inv a b
false
MerkleTree.New.High.fst
MerkleTree.New.High.hash_init
val hash_init (#hsz: pos) : hash #hsz
val hash_init (#hsz: pos) : hash #hsz
let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 36, "end_line": 24, "start_col": 0, "start_line": 23 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz)
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MerkleTree.New.High.hash
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Seq.Base.create", "Lib.IntTypes.uint8", "Lib.IntTypes.u8", "MerkleTree.New.High.hash" ]
[]
false
false
false
false
false
let hash_init (#hsz: pos) : hash #hsz =
Seq.create hsz (Lib.IntTypes.u8 0)
false
OneTimePad.fst
OneTimePad.nib
val nib : Type0
let nib = bool * bool * bool * bool
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 20, "start_col": 0, "start_line": 20 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple4", "Prims.bool" ]
[]
false
false
false
true
true
let nib =
((bool * bool) * bool) * bool
false
OneTimePad.fst
OneTimePad.xor_b
val xor_b : b1: Prims.bool -> b2: Prims.bool -> Prims.bool
let xor_b (b1:bool) (b2:bool) = b1 <> b2
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 21, "start_col": 0, "start_line": 21 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b1: Prims.bool -> b2: Prims.bool -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.op_disEquality" ]
[]
false
false
false
true
false
let xor_b (b1 b2: bool) =
b1 <> b2
false
MerkleTree.New.High.fst
MerkleTree.New.High.seq_slice_more_equal
val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))]
let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 36, "end_line": 53, "start_col": 8, "start_line": 51 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m));
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> n: Prims.nat -> m: Prims.nat{n <= m && m <= FStar.Seq.Base.length s1 && m <= FStar.Seq.Base.length s2} -> k: Prims.nat{n <= k} -> l: Prims.nat{k <= l && l <= m} -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 n m) (FStar.Seq.Base.slice s2 n m)) (ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 k l) (FStar.Seq.Base.slice s2 k l)) [ SMTPat (FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 n m) (FStar.Seq.Base.slice s2 n m)); SMTPat (FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 k l) (FStar.Seq.Base.slice s2 k l)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "Prims.b2t", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "FStar.Seq.Properties.slice_slice", "Prims.op_Subtraction", "Prims.unit" ]
[]
true
false
true
false
false
let seq_slice_more_equal #a s1 s2 n m k l =
slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n)
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.qmont_add_lemma
val qmont_add_lemma: a:S.qelem -> b:S.qelem -> Lemma (S.qadd (from_qmont a) (from_qmont b) = from_qmont ((a + b) % S.order))
val qmont_add_lemma: a:S.qelem -> b:S.qelem -> Lemma (S.qadd (from_qmont a) (from_qmont b) = from_qmont ((a + b) % S.order))
let qmont_add_lemma a b = mont_add_lemma_gen S.order qmont_R_inv a b
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 295, "start_col": 0, "start_line": 294 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //-------------------------- let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a let lemma_from_to_qmont_id a = mul_qmont_R_and_R_inv_is_one (); Math.Lemmas.swap_mul qmont_R qmont_R_inv; lemma_from_to_mont_id_gen S.order qmont_R qmont_R_inv a
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.P256.PointOps.qelem -> b: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures Spec.P256.PointOps.qadd (Hacl.Spec.P256.Montgomery.from_qmont a) (Hacl.Spec.P256.Montgomery.from_qmont b) = Hacl.Spec.P256.Montgomery.from_qmont ((a + b) % Spec.P256.PointOps.order))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Hacl.Spec.P256.Montgomery.mont_add_lemma_gen", "Spec.P256.PointOps.order", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Prims.unit" ]
[]
true
false
true
false
false
let qmont_add_lemma a b =
mont_add_lemma_gen S.order qmont_R_inv a b
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.lemma_to_from_qmont_id
val lemma_to_from_qmont_id: a:S.qelem -> Lemma (from_qmont (to_qmont a) == a)
val lemma_to_from_qmont_id: a:S.qelem -> Lemma (from_qmont (to_qmont a) == a)
let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 285, "start_col": 0, "start_line": 283 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //--------------------------
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.Montgomery.from_qmont (Hacl.Spec.P256.Montgomery.to_qmont a) == a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Hacl.Spec.P256.Montgomery.lemma_to_from_mont_id_gen", "Spec.P256.PointOps.order", "Hacl.Spec.P256.Montgomery.qmont_R", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Prims.unit", "Hacl.Spec.P256.Montgomery.mul_qmont_R_and_R_inv_is_one" ]
[]
true
false
true
false
false
let lemma_to_from_qmont_id a =
mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a
false
OneTimePad.fst
OneTimePad.xor
val xor : _: (((Prims.bool * Prims.bool) * Prims.bool) * Prims.bool) -> _: (((Prims.bool * Prims.bool) * Prims.bool) * Prims.bool) -> ((Prims.bool * Prims.bool) * Prims.bool) * Prims.bool
let xor (a, b, c, d) (w, x, y, z) = (a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z)
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 89, "end_line": 22, "start_col": 0, "start_line": 22 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: (((Prims.bool * Prims.bool) * Prims.bool) * Prims.bool) -> _: (((Prims.bool * Prims.bool) * Prims.bool) * Prims.bool) -> ((Prims.bool * Prims.bool) * Prims.bool) * Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple4", "Prims.bool", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.Mktuple4", "OneTimePad.xor_b" ]
[]
false
false
false
true
false
let xor (a, b, c, d) (w, x, y, z) =
(a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z)
false
MerkleTree.New.High.fst
MerkleTree.New.High.path_insert
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz)
let path_insert #_ p hp = S.snoc p hp
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 37, "end_line": 380, "start_col": 0, "start_line": 380 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = ()
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: MerkleTree.New.High.path -> hp: MerkleTree.New.High.hash -> Prims.GTot MerkleTree.New.High.path
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.path", "MerkleTree.New.High.hash", "FStar.Seq.Properties.snoc" ]
[]
false
false
false
false
false
let path_insert #_ p hp =
S.snoc p hp
false
OneTimePad.fst
OneTimePad.bind
val bind (a b: Type) (x: random a) (f: (a -> random b)) : random b
val bind (a b: Type) (x: random a) (f: (a -> random b)) : random b
let bind (a b : Type) (x:random a) (f: a -> random b) : random b = fun store -> let (z, n) = x store in f z (n, snd store)
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 36, "start_col": 0, "start_line": 32 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool let xor_b (b1:bool) (b2:bool) = b1 <> b2 let xor (a, b, c, d) (w, x, y, z) = (a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z) let xor_properties (x:nib) (y:nib) = assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x) type tape = int -> Tot nib type random (a:Type) = (int * (int -> Tot nib)) -> M (a * int)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> x: OneTimePad.random a -> f: (_: a -> OneTimePad.random b) -> OneTimePad.random b
Prims.Tot
[ "total" ]
[]
[ "OneTimePad.random", "FStar.Pervasives.Native.tuple2", "Prims.int", "OneTimePad.nib", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.snd" ]
[]
false
false
false
true
false
let bind (a b: Type) (x: random a) (f: (a -> random b)) : random b =
fun store -> let z, n = x store in f z (n, snd store)
false
OneTimePad.fst
OneTimePad.return
val return (a: Type) (x: a) : random a
val return (a: Type) (x: a) : random a
let return (a:Type) (x:a) : random a = fun s -> (x, fst s)
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 31, "start_col": 0, "start_line": 31 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool let xor_b (b1:bool) (b2:bool) = b1 <> b2 let xor (a, b, c, d) (w, x, y, z) = (a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z) let xor_properties (x:nib) (y:nib) = assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x) type tape = int -> Tot nib
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> x: a -> OneTimePad.random a
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Prims.int", "OneTimePad.nib", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.fst", "OneTimePad.random" ]
[]
false
false
false
true
false
let return (a: Type) (x: a) : random a =
fun s -> (x, fst s)
false
OneTimePad.fst
OneTimePad.rand
val rand: Prims.unit -> random nib
val rand: Prims.unit -> random nib
let rand () : random nib = fun store -> let n, tape = store in tape n, n + 1
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 39, "start_col": 0, "start_line": 37 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool let xor_b (b1:bool) (b2:bool) = b1 <> b2 let xor (a, b, c, d) (w, x, y, z) = (a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z) let xor_properties (x:nib) (y:nib) = assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x) type tape = int -> Tot nib type random (a:Type) = (int * (int -> Tot nib)) -> M (a * int) let return (a:Type) (x:a) : random a = fun s -> (x, fst s) let bind (a b : Type) (x:random a) (f: a -> random b) : random b = fun store -> let (z, n) = x store in
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> OneTimePad.random OneTimePad.nib
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Pervasives.Native.tuple2", "Prims.int", "OneTimePad.nib", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "OneTimePad.random" ]
[]
false
false
false
true
false
let rand () : random nib =
fun store -> let n, tape = store in tape n, n + 1
false
OneTimePad.fst
OneTimePad.id_nib
val id_nib : x: OneTimePad.nib -> OneTimePad.nib
let id_nib (x:nib) = x
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 60, "start_col": 0, "start_line": 60 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool let xor_b (b1:bool) (b2:bool) = b1 <> b2 let xor (a, b, c, d) (w, x, y, z) = (a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z) let xor_properties (x:nib) (y:nib) = assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x) type tape = int -> Tot nib type random (a:Type) = (int * (int -> Tot nib)) -> M (a * int) let return (a:Type) (x:a) : random a = fun s -> (x, fst s) let bind (a b : Type) (x:random a) (f: a -> random b) : random b = fun store -> let (z, n) = x store in f z (n, snd store) let rand () : random nib = fun store -> let n, tape = store in tape n, n + 1 total reifiable reflectable new_effect { RANDOM : a:Type -> Effect with repr = random ; bind = bind ; return = return ; rand = rand } effect Rand (a:Type) = RANDOM a (fun initial_tape post -> forall (x:(a * int)). post x) let one_time_pad () : Rand ((nib -> nib) * (nib -> nib)) = let key = RANDOM?.rand () in let encrypt (msg:nib) = msg `xor` key in let decrypt (cipher:nib) = cipher `xor` key in encrypt, decrypt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: OneTimePad.nib -> OneTimePad.nib
Prims.Tot
[ "total" ]
[]
[ "OneTimePad.nib" ]
[]
false
false
false
true
false
let id_nib (x: nib) =
x
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_wf_elts
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0
let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 21, "end_line": 136, "start_col": 0, "start_line": 135 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: MerkleTree.New.High.merkle_tree -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "Prims.nat", "Prims.b2t", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.pow2", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.bool", "MerkleTree.New.High.hash", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hs_wf_elts" ]
[]
false
false
false
false
true
let mt_wf_elts #_ (MT i j hs _ _ _ _) =
hs_wf_elts 0 hs i j
false
OneTimePad.fst
OneTimePad.xor_properties
val xor_properties : x: OneTimePad.nib -> y: OneTimePad.nib -> Prims.unit
let xor_properties (x:nib) (y:nib) = assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x)
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 27, "start_col": 0, "start_line": 23 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool let xor_b (b1:bool) (b2:bool) = b1 <> b2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: OneTimePad.nib -> y: OneTimePad.nib -> Prims.unit
Prims.Tot
[ "total" ]
[]
[ "OneTimePad.nib", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "FStar.Pervasives.Native.tuple4", "Prims.bool", "OneTimePad.xor", "Prims.unit" ]
[]
false
false
false
true
false
let xor_properties (x y: nib) =
assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x)
false
MerkleTree.New.High.fst
MerkleTree.New.High.offset_of
val offset_of: i:nat -> Tot nat
val offset_of: i:nat -> Tot nat
let offset_of i = if i % 2 = 0 then i else i - 1
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 32, "end_line": 96, "start_col": 0, "start_line": 95 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.bool", "Prims.op_Subtraction" ]
[]
false
false
false
true
false
let offset_of i =
if i % 2 = 0 then i else i - 1
false
LowStar.RVector.fst
LowStar.RVector.flush
val flush: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t{i <= V.size_of rv} -> HST.ST (rvector rg) (requires (fun h0 -> rv_inv h0 rv)) (ensures (fun h0 frv h1 -> V.size_of frv = V.size_of rv - i /\ V.frameOf rv = V.frameOf frv /\ modifies (loc_rvector rv) h0 h1 /\ rv_inv h1 frv /\ S.equal (as_seq h1 frv) (S.slice (as_seq h0 rv) (U32.v i) (U32.v (V.size_of rv)))))
val flush: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t{i <= V.size_of rv} -> HST.ST (rvector rg) (requires (fun h0 -> rv_inv h0 rv)) (ensures (fun h0 frv h1 -> V.size_of frv = V.size_of rv - i /\ V.frameOf rv = V.frameOf frv /\ modifies (loc_rvector rv) h0 h1 /\ rv_inv h1 frv /\ S.equal (as_seq h1 frv) (S.slice (as_seq h0 rv) (U32.v i) (U32.v (V.size_of rv)))))
let flush #a #rst #rg rv i = let hh0 = HST.get () in (if i = 0ul then () else free_elems rv (i - 1ul)); rv_loc_elems_included hh0 rv 0ul i; let hh1 = HST.get () in assert (modifies (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) hh0 hh1); let frv = V.flush rv (rg_dummy rg) i in let hh2 = HST.get () in assert (modifies (loc_region_only false (V.frameOf rv)) hh1 hh2); // Safety rs_loc_elems_disj rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i) (U32.v i) (U32.v (V.size_of rv)); rs_loc_elems_parent_disj rg (V.as_seq hh0 rv) (V.frameOf rv) (U32.v i) (U32.v (V.size_of rv)); rs_elems_inv_preserved rg (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)) (loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) (loc_region_only false (V.frameOf rv))) hh0 hh2; assert (rv_inv #a #rst #rg hh2 frv); // Correctness as_seq_seq_preserved rg (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)) (loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) (loc_region_only false (V.frameOf rv))) hh0 hh2; as_seq_seq_slice rg hh0 (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv)) (U32.v i) (U32.v (V.size_of rv)); assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))) (as_seq_seq rg hh2 (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))); as_seq_seq_eq rg hh2 (V.as_seq hh0 rv) (V.as_seq hh2 frv) (U32.v i) (U32.v (V.size_of rv)) 0 (U32.v (V.size_of frv)); assert (S.equal (as_seq_seq rg hh2 (V.as_seq hh2 frv) 0 (U32.v (V.size_of frv))) (as_seq_seq rg hh2 (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))); assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))) (as_seq hh2 frv)); frv
{ "file_name": "ulib/LowStar.RVector.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 1079, "start_col": 0, "start_line": 1032 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.RVector open FStar.Classical open FStar.Integers open LowStar.Modifies open LowStar.Regional open LowStar.Vector module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module S = FStar.Seq module B = LowStar.Buffer module V = LowStar.Vector module U32 = FStar.UInt32 /// Utilities /// A `regional` type `a` is also `copyable` when there exists a copy operator /// that guarantees the same representation between `src` and `dst`. /// For instance, the `copy` operation for `B.buffer a` is `B.blit`. /// /// Here, no reference at run-time is kept to the state argument of the /// regional; conceivably, the caller will already have some reference handy to /// the instance of the regional class and can retrieve the parameter from /// there. inline_for_extraction noeq type copyable (#rst:Type) (a:Type0) (rg:regional rst a) = | Cpy: copy: (s:rst{s==Rgl?.state rg} -> src:a -> dst:a -> HST.ST unit (requires (fun h0 -> rg_inv rg h0 src /\ rg_inv rg h0 dst /\ HS.disjoint (Rgl?.region_of rg src) (Rgl?.region_of rg dst))) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (Rgl?.region_of rg dst)) h0 h1 /\ rg_inv rg h1 dst /\ Rgl?.r_repr rg h1 dst == Rgl?.r_repr rg h0 src))) -> copyable a rg // rst: regional state type rvector (#a:Type0) (#rst:Type) (rg:regional rst a) = V.vector a val loc_rvector: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> GTot loc let loc_rvector #a #rst #rg rv = loc_all_regions_from false (V.frameOf rv) /// The invariant of `rvector` // Here we will define the invariant for `rvector #a` that contains // the invariant for each element and some more about the vector itself. val rs_elems_inv: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length rs} -> GTot Type0 let rs_elems_inv #a #rst rg h rs i j = V.forall_seq rs i j (rg_inv rg h) val rv_elems_inv: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> GTot Type0 let rv_elems_inv #a #rst #rg h rv i j = rs_elems_inv rg h (V.as_seq h rv) (U32.v i) (U32.v j) val elems_inv: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> GTot Type0 let elems_inv #a #rst #rg h rv = rv_elems_inv h rv 0ul (V.size_of rv) val rs_elems_reg: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> GTot Type0 let rs_elems_reg #a #rst rg rs prid i j = V.forall_seq rs i j (fun v -> HS.extends (Rgl?.region_of rg v) prid) /\ V.forall2_seq rs i j (fun v1 v2 -> HS.disjoint (Rgl?.region_of rg v1) (Rgl?.region_of rg v2)) val rv_elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> GTot Type0 let rv_elems_reg #a #rst #rg h rv i j = rs_elems_reg rg (V.as_seq h rv) (V.frameOf rv) (U32.v i) (U32.v j) val elems_reg: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> GTot Type0 let elems_reg #a #rst #rg h rv = rv_elems_reg h rv 0ul (V.size_of rv) val rv_itself_inv: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> GTot Type0 let rv_itself_inv #a #rst #rg h rv = V.live h rv /\ V.freeable rv /\ HST.is_eternal_region (V.frameOf rv) // This is the invariant of `rvector`. val rv_inv: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> GTot Type0 let rv_inv #a #rst #rg h rv = elems_inv h rv /\ elems_reg h rv /\ rv_itself_inv h rv val rs_elems_inv_live_region: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length rs} -> Lemma (requires (rs_elems_inv rg h rs i j)) (ensures (V.forall_seq rs i j (fun r -> HS.live_region h (Rgl?.region_of rg r)))) let rec rs_elems_inv_live_region #a #rst rg h rs i j = if i = j then () else (Rgl?.r_inv_reg rg h (S.index rs (j - 1)); rs_elems_inv_live_region rg h rs i (j - 1)) val rv_elems_inv_live_region: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (rv_elems_inv h rv i j)) (ensures (V.forall_ h rv i j (fun r -> HS.live_region h (Rgl?.region_of rg r)))) let rv_elems_inv_live_region #a #rst #rg h rv i j = rs_elems_inv_live_region rg h (V.as_seq h rv) (U32.v i) (U32.v j) /// Utilities for fine-grained region control val rs_loc_elem: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> i:nat{i < S.length rs} -> GTot loc let rs_loc_elem #a #rst rg rs i = loc_all_regions_from false (Rgl?.region_of rg (S.index rs i)) val rs_loc_elems: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length rs} -> GTot loc (decreases j) let rec rs_loc_elems #a #rst rg rs i j = if i = j then loc_none else loc_union (rs_loc_elems rg rs i (j - 1)) (rs_loc_elem rg rs (j - 1)) val rv_loc_elems: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> GTot loc let rv_loc_elems #a #rst #rg h rv i j = rs_loc_elems rg (V.as_seq h rv) (U32.v i) (U32.v j) val rv_loc_elem: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t{i < V.size_of rv} -> GTot loc let rv_loc_elem #a #rst #rg h rv i = rs_loc_elems rg (V.as_seq h rv) (U32.v i) (U32.v i+1) // Properties about inclusion of locations val rs_loc_elems_rec_inverse: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> i:nat -> j:nat{i < j && j <= S.length rs} -> Lemma (requires true) (ensures (rs_loc_elems rg rs i j == loc_union (rs_loc_elem rg rs i) (rs_loc_elems rg rs (i + 1) j))) (decreases j) let rec rs_loc_elems_rec_inverse #a #rst rg rs i j = if i + 1 = j then () else (assert (rs_loc_elems rg rs i j == loc_union (rs_loc_elems rg rs i (j - 1)) (rs_loc_elem rg rs (j - 1))); assert (rs_loc_elems rg rs (i + 1) j == loc_union (rs_loc_elems rg rs (i + 1) (j - 1)) (rs_loc_elem rg rs (j - 1))); rs_loc_elems_rec_inverse rg rs i (j - 1); assert (rs_loc_elems rg rs i j == loc_union (loc_union (rs_loc_elem rg rs i) (rs_loc_elems rg rs (i + 1) (j - 1))) (rs_loc_elem rg rs (j - 1))); loc_union_assoc (rs_loc_elem rg rs i) (rs_loc_elems rg rs (i + 1) (j - 1)) (rs_loc_elem rg rs (j - 1))) val rs_loc_elems_includes: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length rs} -> k:nat{i <= k && k < j} -> Lemma (loc_includes (rs_loc_elems rg rs i j) (rs_loc_elem rg rs k)) let rec rs_loc_elems_includes #a #rst rg rs i j k = if k = j - 1 then () else rs_loc_elems_includes #a #rst rg rs i (j - 1) k val loc_all_exts_from: preserve_liveness: bool -> r: HS.rid -> GTot loc let loc_all_exts_from preserve_liveness r = B.loc_regions preserve_liveness (Set.intersect (HS.mod_set (Set.singleton r)) (Set.complement (Set.singleton r))) val rs_loc_elem_included: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat{i < S.length rs} -> Lemma (requires (HS.extends (Rgl?.region_of rg (S.index rs i)) prid)) (ensures (loc_includes (loc_all_exts_from false prid) (rs_loc_elem rg rs i))) let rs_loc_elem_included #a #rst rg rs prid i = () val rs_loc_elems_included: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> Lemma (requires (rs_elems_reg rg rs prid i j)) (ensures (loc_includes (loc_all_exts_from false prid) (rs_loc_elems rg rs i j))) (decreases j) let rec rs_loc_elems_included #a #rst rg rs prid i j = if i = j then () else (rs_loc_elem_included rg rs prid (j - 1); rs_loc_elems_included rg rs prid i (j - 1)) val rv_loc_elems_included: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (rv_elems_reg h rv i j)) (ensures (loc_includes (loc_all_exts_from false (V.frameOf rv)) (rv_loc_elems h rv i j))) let rv_loc_elems_included #a #rst #rg h rv i j = rs_loc_elems_included rg (V.as_seq h rv) (V.frameOf rv) (U32.v i) (U32.v j) // Properties about disjointness of locations val rs_loc_elem_disj: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> k:nat{i <= k && k < j} -> l:nat{i <= l && l < j && k <> l} -> Lemma (requires (rs_elems_reg rg rs prid i j)) (ensures (loc_disjoint (rs_loc_elem rg rs k) (rs_loc_elem rg rs l))) let rs_loc_elem_disj #a #rst rg rs prid i j k l = () val rs_loc_elem_disj_forall: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> Lemma (requires (rs_elems_reg rg rs prid i j)) (ensures ( forall (k:nat{i <= k && k < j}). forall (l:nat{i <= l && l < j && k <> l}). loc_disjoint (rs_loc_elem rg rs k) (rs_loc_elem rg rs l))) let rs_loc_elem_disj_forall #a #rst rg rs prid i j = () val rs_loc_elems_elem_disj: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> k1:nat{i <= k1} -> k2:nat{k1 <= k2 && k2 <= j} -> l:nat{i <= l && l < j && (l < k1 || k2 <= l)} -> Lemma (requires (rs_elems_reg rg rs prid i j)) (ensures (loc_disjoint (rs_loc_elems rg rs k1 k2) (rs_loc_elem rg rs l))) (decreases k2) let rec rs_loc_elems_elem_disj #a #rst rg rs prid i j k1 k2 l = if k1 = k2 then () else (rs_loc_elem_disj rg rs prid i j (k2 - 1) l; rs_loc_elems_elem_disj rg rs prid i j k1 (k2 - 1) l) val rs_loc_elems_disj: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> k1:nat{i <= k1} -> k2:nat{k1 <= k2 && k2 <= j} -> l1:nat{i <= l1} -> l2:nat{l1 <= l2 && l2 <= j} -> Lemma (requires (rs_elems_reg rg rs prid i j /\ (k2 <= l1 || l2 <= k1))) (ensures (loc_disjoint (rs_loc_elems rg rs k1 k2) (rs_loc_elems rg rs l1 l2))) (decreases k2) let rec rs_loc_elems_disj #a #rst rg rs prid i j k1 k2 l1 l2 = if k1 = k2 then () else (rs_loc_elems_elem_disj rg rs prid i j l1 l2 (k2 - 1); rs_loc_elems_disj rg rs prid i j k1 (k2 - 1) l1 l2) val rv_loc_elems_disj: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> k1:uint32_t{i <= k1} -> k2:uint32_t{k1 <= k2 && k2 <= j} -> l1:uint32_t{i <= l1} -> l2:uint32_t{l1 <= l2 && l2 <= j} -> Lemma (requires (rv_elems_reg h rv i j /\ (k2 <= l1 || l2 <= k1))) (ensures (loc_disjoint (rv_loc_elems h rv k1 k2) (rv_loc_elems h rv l1 l2))) let rv_loc_elems_disj #a #rst #rg h rv i j k1 k2 l1 l2 = rs_loc_elems_disj rg (V.as_seq h rv) (V.frameOf rv) (U32.v i) (U32.v j) (U32.v k1) (U32.v k2) (U32.v l1) (U32.v l2) val rs_loc_elems_parent_disj: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> prid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> Lemma (requires (rs_elems_reg rg rs prid i j)) (ensures (loc_disjoint (rs_loc_elems rg rs i j) (loc_region_only false prid))) (decreases j) let rec rs_loc_elems_parent_disj #a #rst rg rs prid i j = if i = j then () else rs_loc_elems_parent_disj rg rs prid i (j - 1) val rv_loc_elems_parent_disj: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> Lemma (requires (rv_elems_reg h rv i j)) (ensures (loc_disjoint (rv_loc_elems h rv i j) (loc_region_only false (V.frameOf rv)))) let rv_loc_elems_parent_disj #a #rst #rg h rv i j = rs_loc_elems_parent_disj rg (V.as_seq h rv) (V.frameOf rv) (U32.v i) (U32.v j) val rs_loc_elems_each_disj: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> drid:HS.rid -> i:nat -> j:nat{i <= j && j <= S.length rs} -> Lemma (requires (V.forall_seq rs i j (fun r -> HS.disjoint (Rgl?.region_of rg r) drid))) (ensures (loc_disjoint (rs_loc_elems rg rs i j) (loc_all_regions_from false drid))) (decreases j) let rec rs_loc_elems_each_disj #a #rst rg rs drid i j = if i = j then () else rs_loc_elems_each_disj rg rs drid i (j - 1) val rv_loc_elems_each_disj: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> drid:HS.rid -> Lemma (requires (V.forall_ h rv i j (fun r -> HS.disjoint (Rgl?.region_of rg r) drid))) (ensures (loc_disjoint (rv_loc_elems h rv i j) (loc_all_regions_from false drid))) let rv_loc_elems_each_disj #a #rst #rg h rv i j drid = rs_loc_elems_each_disj rg (V.as_seq h rv) drid (U32.v i) (U32.v j) // Preservation based on disjointness val rv_loc_elems_preserved: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 rv /\ loc_disjoint p (V.loc_vector_within rv i j) /\ modifies p h0 h1)) (ensures (rv_loc_elems h0 rv i j == rv_loc_elems h1 rv i j)) (decreases (U32.v j)) let rec rv_loc_elems_preserved #a #rst #rg rv i j p h0 h1 = if i = j then () else (V.loc_vector_within_includes rv i j (j - 1ul) j; V.get_preserved rv (j - 1ul) p h0 h1; assert (V.get h0 rv (j - 1ul) == V.get h1 rv (j - 1ul)); V.loc_vector_within_includes rv i j i (j - 1ul); rv_loc_elems_preserved rv i (j - 1ul) p h0 h1) val rs_elems_inv_preserved: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length rs} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rs_elems_inv rg h0 rs i j /\ loc_disjoint p (rs_loc_elems rg rs i j) /\ modifies p h0 h1)) (ensures (rs_elems_inv rg h1 rs i j)) (decreases j) let rec rs_elems_inv_preserved #a #rst rg rs i j p h0 h1 = if i = j then () else (rs_elems_inv_preserved rg rs i (j - 1) p h0 h1; Rgl?.r_sep rg (S.index rs (j - 1)) p h0 h1) val rv_elems_inv_preserved: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 rv /\ rv_elems_inv h0 rv i j /\ loc_disjoint p (V.loc_vector rv) /\ loc_disjoint p (rv_loc_elems h0 rv i j) /\ modifies p h0 h1)) (ensures (rv_elems_inv h1 rv i j)) let rv_elems_inv_preserved #a #rst #rg rv i j p h0 h1 = rs_elems_inv_preserved rg (V.as_seq h0 rv) (U32.v i) (U32.v j) p h0 h1 val rv_inv_preserved_: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rv_inv h0 rv /\ loc_disjoint p (loc_vector rv) /\ loc_disjoint p (rv_loc_elems h0 rv 0ul (V.size_of rv)) /\ modifies p h0 h1)) (ensures (rv_inv h1 rv)) let rv_inv_preserved_ #a #rst #rg rv p h0 h1 = rv_elems_inv_preserved #a #rst #rg rv 0ul (V.size_of rv) p h0 h1 // The first core lemma of `rvector` val rv_inv_preserved: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rv_inv h0 rv /\ loc_disjoint p (loc_rvector rv) /\ modifies p h0 h1)) (ensures (rv_inv h1 rv)) [SMTPat (rv_inv h0 rv); SMTPat (loc_disjoint p (loc_rvector rv)); SMTPat (modifies p h0 h1)] let rv_inv_preserved #a #rst #rg rv p h0 h1 = assert (loc_includes (loc_rvector rv) (V.loc_vector rv)); rv_loc_elems_included h0 rv 0ul (V.size_of rv); assert (loc_includes (loc_rvector rv) (rv_loc_elems h0 rv 0ul (V.size_of rv))); rv_inv_preserved_ rv p h0 h1 val rv_inv_preserved_int: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t{i < V.size_of rv} -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rv_inv h0 rv /\ modifies (loc_all_regions_from false (Rgl?.region_of rg (V.get h0 rv i))) h0 h1 /\ rg_inv rg h1 (V.get h1 rv i))) (ensures (rv_inv h1 rv)) let rv_inv_preserved_int #a #rst #rg rv i h0 h1 = rs_loc_elems_elem_disj rg (V.as_seq h0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i) (U32.v i); rs_elems_inv_preserved rg (V.as_seq h0 rv) 0 (U32.v i) (loc_all_regions_from false (Rgl?.region_of rg (V.get h1 rv i))) h0 h1; rs_loc_elems_elem_disj rg (V.as_seq h0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)) (U32.v i + 1) (U32.v (V.size_of rv)) (U32.v i); rs_elems_inv_preserved rg (V.as_seq h0 rv) (U32.v i + 1) (U32.v (V.size_of rv)) (loc_all_regions_from false (Rgl?.region_of rg (V.get h1 rv i))) h0 h1 /// Representation val as_seq_seq: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs:S.seq a -> i:nat -> j:nat{i <= j /\ j <= S.length rs /\ rs_elems_inv rg h rs i j} -> GTot (s:S.seq (Rgl?.repr rg){S.length s = j - i}) (decreases j) let rec as_seq_seq #a #rst rg h rs i j = if i = j then S.empty else S.snoc (as_seq_seq rg h rs i (j - 1)) (Rgl?.r_repr rg h (S.index rs (j - 1))) val as_seq_sub: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg -> i:uint32_t -> j:uint32_t{ i <= j /\ j <= V.size_of rv /\ rv_elems_inv h rv i j} -> GTot (s:S.seq (Rgl?.repr rg){S.length s = U32.v j - U32.v i}) (decreases (U32.v j)) let as_seq_sub #a #rst #rg h rv i j = as_seq_seq rg h (V.as_seq h rv) (U32.v i) (U32.v j) val as_seq: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg{rv_inv h rv} -> GTot (s:S.seq (Rgl?.repr rg){S.length s = U32.v (V.size_of rv)}) let as_seq #a #rst #rg h rv = as_seq_sub h rv 0ul (V.size_of rv) val as_seq_sub_as_seq: #a:Type0 -> #rst:Type -> #rg:regional rst a -> h:HS.mem -> rv:rvector rg{rv_inv h rv} -> Lemma (S.equal (as_seq_sub h rv 0ul (V.size_of rv)) (as_seq h rv)) [SMTPat (as_seq_sub h rv 0ul (V.size_of rv))] let as_seq_sub_as_seq #a #rst #rg h rv = () val as_seq_seq_index: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs:S.seq a -> i:nat -> j:nat{i <= j /\ j <= S.length rs /\ rs_elems_inv rg h rs i j} -> k:nat{k < j - i} -> Lemma (requires true) (ensures (S.index (as_seq_seq rg h rs i j) k == Rgl?.r_repr rg h (S.index rs (i + k)))) (decreases j) [SMTPat (S.index (as_seq_seq rg h rs i j) k)] let rec as_seq_seq_index #a #rst rg h rs i j k = if i = j then () else if k = j - i - 1 then () else as_seq_seq_index rg h rs i (j - 1) k val as_seq_seq_eq: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs1:S.seq a -> rs2:S.seq a -> i:nat -> j:nat{i <= j /\ j <= S.length rs1 /\ rs_elems_inv rg h rs1 i j} -> k:nat -> l:nat{k <= l /\ l <= S.length rs2 /\ rs_elems_inv rg h rs2 k l} -> Lemma (requires (S.equal (S.slice rs1 i j) (S.slice rs2 k l))) (ensures (S.equal (as_seq_seq rg h rs1 i j) (as_seq_seq rg h rs2 k l))) let as_seq_seq_eq #a #rst rg h rs1 rs2 i j k l = assert (forall (a:nat{a < j - i}). S.index (as_seq_seq rg h rs1 i j) a == Rgl?.r_repr rg h (S.index rs1 (i + a))); assert (forall (a:nat{a < l - k}). S.index (as_seq_seq rg h rs2 k l) a == Rgl?.r_repr rg h (S.index rs2 (k + a))); assert (S.length (S.slice rs1 i j) = j - i); assert (S.length (S.slice rs2 k l) = l - k); assert (forall (a:nat{a < j - i}). S.index (S.slice rs1 i j) a == S.index (S.slice rs2 k l) a); assert (forall (a:nat{a < j - i}). S.index rs1 (i + a) == S.index rs2 (k + a)) val as_seq_seq_slice: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs:S.seq a -> i:nat -> j:nat{i <= j /\ j <= S.length rs /\ rs_elems_inv rg h rs i j} -> k:nat -> l:nat{k <= l && l <= j - i} -> Lemma (S.equal (S.slice (as_seq_seq rg h rs i j) k l) (as_seq_seq rg h (S.slice rs (i + k) (i + l)) 0 (l - k))) #reset-options "--z3rlimit 10" let rec as_seq_seq_slice #a #rst rg h rs i j k l = if k = l then () else (as_seq_seq_slice rg h rs i j k (l - 1); as_seq_seq_index rg h rs i j (l - 1); as_seq_seq_eq rg h (S.slice rs (i + k) (i + l - 1)) (S.slice rs (i + k) (i + l)) 0 (l - k - 1) 0 (l - k - 1)) val as_seq_seq_upd: #a:Type0 -> #rst:Type -> rg:regional rst a -> h:HS.mem -> rs:S.seq a -> i:nat -> j:nat{ i <= j /\ j <= S.length rs /\ rs_elems_inv rg h rs i j} -> k:nat{i <= k && k < j} -> v:a{rg_inv rg h v} -> Lemma (S.equal (as_seq_seq rg h (S.upd rs k v) i j) (S.upd (as_seq_seq rg h rs i j) (k - i) (Rgl?.r_repr rg h v))) let rec as_seq_seq_upd #a #rst rg h rs i j k v = if i = j then () else if k = j - 1 then () else as_seq_seq_upd rg h rs i (j - 1) k v // Preservation based on disjointness val as_seq_seq_preserved: #a:Type0 -> #rst:Type -> rg:regional rst a -> rs:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length rs} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rs_elems_inv rg h0 rs i j /\ loc_disjoint p (rs_loc_elems rg rs i j) /\ modifies p h0 h1)) (ensures (rs_elems_inv_preserved rg rs i j p h0 h1; S.equal (as_seq_seq rg h0 rs i j) (as_seq_seq rg h1 rs i j))) let rec as_seq_seq_preserved #a #rst rg rs i j p h0 h1 = if i = j then () else (rs_elems_inv_preserved rg rs i (j - 1) p h0 h1; as_seq_seq_preserved rg rs i (j - 1) p h0 h1; Rgl?.r_sep rg (S.index rs (j - 1)) p h0 h1) val as_seq_sub_preserved: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t -> j:uint32_t{i <= j && j <= V.size_of rv} -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (V.live h0 rv /\ rv_elems_inv h0 rv i j /\ loc_disjoint p (rv_loc_elems h0 rv i j) /\ loc_disjoint p (V.loc_vector rv) /\ modifies p h0 h1)) (ensures (rv_elems_inv_preserved rv i j p h0 h1; S.equal (as_seq_sub h0 rv i j) (as_seq_sub h1 rv i j))) let as_seq_sub_preserved #a #rst #rg rv i j p h0 h1 = as_seq_seq_preserved rg (V.as_seq h0 rv) (U32.v i) (U32.v j) p h0 h1 val as_seq_preserved_: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rv_inv h0 rv /\ loc_disjoint p (loc_vector rv) /\ loc_disjoint p (rv_loc_elems h0 rv 0ul (V.size_of rv)) /\ modifies p h0 h1)) (ensures (rv_inv_preserved_ rv p h0 h1; S.equal (as_seq h0 rv) (as_seq h1 rv))) let as_seq_preserved_ #a #rst #rg rv p h0 h1 = as_seq_sub_preserved rv 0ul (V.size_of rv) p h0 h1 // The second core lemma of `rvector` val as_seq_preserved: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> p:loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (rv_inv h0 rv /\ loc_disjoint p (loc_rvector rv) /\ modifies p h0 h1)) (ensures (rv_inv_preserved rv p h0 h1; S.equal (as_seq h0 rv) (as_seq h1 rv))) [SMTPat (rv_inv h0 rv); SMTPat (loc_disjoint p (loc_rvector rv)); SMTPat (modifies p h0 h1)] let as_seq_preserved #a #rst #rg rv p h0 h1 = assert (loc_includes (loc_rvector rv) (V.loc_vector rv)); rv_loc_elems_included h0 rv 0ul (V.size_of rv); assert (loc_includes (loc_rvector rv) (rv_loc_elems h0 rv 0ul (V.size_of rv))); as_seq_preserved_ rv p h0 h1 /// Construction val alloc_empty: #a:Type0 -> #rst:Type -> rg:regional rst a -> HST.ST (rvector rg) (requires (fun h0 -> true)) (ensures (fun h0 bv h1 -> h0 == h1 /\ V.size_of bv = 0ul)) let alloc_empty #a #rst rg = V.alloc_empty a val alloc_: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> cidx:uint32_t{cidx <= V.size_of rv} -> HST.ST unit (requires (fun h0 -> rv_itself_inv h0 rv)) (ensures (fun h0 _ h1 -> modifies (V.loc_vector_within rv 0ul cidx) h0 h1 /\ rv_itself_inv h1 rv /\ rv_elems_inv h1 rv 0ul cidx /\ rv_elems_reg h1 rv 0ul cidx /\ S.equal (as_seq_sub h1 rv 0ul cidx) (S.create (U32.v cidx) (Ghost.reveal (Rgl?.irepr rg))) /\ // the loop invariant for this function V.forall_ h1 rv 0ul cidx (fun r -> HS.fresh_region (Rgl?.region_of rg r) h0 h1 /\ Rgl?.r_alloc_p rg r) /\ Set.subset (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)))) (decreases (U32.v cidx)) #reset-options "--z3rlimit 20" let rec alloc_ #a #rst #rg rv cidx = let hh0 = HST.get () in if cidx = 0ul then () else (let nrid = HST.new_region (V.frameOf rv) in let v = rg_alloc rg nrid in let hh1 = HST.get () in V.assign rv (cidx - 1ul) v; let hh2 = HST.get () in V.loc_vector_within_included rv (cidx - 1ul) cidx; Rgl?.r_sep rg (V.get hh2 rv (cidx - 1ul)) (V.loc_vector_within rv (cidx - 1ul) cidx) hh1 hh2; alloc_ rv (cidx - 1ul); let hh3 = HST.get () in V.loc_vector_within_included rv 0ul (cidx - 1ul); Rgl?.r_sep rg (V.get hh3 rv (cidx - 1ul)) (V.loc_vector_within rv 0ul (cidx - 1ul)) hh2 hh3; V.forall2_extend hh3 rv 0ul (cidx - 1ul) (fun r1 r2 -> HS.disjoint (Rgl?.region_of rg r1) (Rgl?.region_of rg r2)); V.loc_vector_within_union_rev rv 0ul cidx) val alloc_rid: #a:Type0 -> #rst:Type -> rg:regional rst a -> len:uint32_t{len > 0ul} -> rid:HST.erid -> HST.ST (rvector rg) (requires (fun h0 -> true)) (ensures (fun h0 rv h1 -> modifies (V.loc_vector rv) h0 h1 /\ rv_inv h1 rv /\ V.frameOf rv = rid /\ V.size_of rv = len /\ V.forall_all h1 rv (fun r -> Rgl?.r_alloc_p rg r) /\ S.equal (as_seq h1 rv) (S.create (U32.v len) (Ghost.reveal (Rgl?.irepr rg))))) let alloc_rid #a #rst rg len rid = let vec = V.alloc_rid len (rg_dummy rg) rid in alloc_ #a #rst #rg vec len; V.loc_vector_within_included vec 0ul len; vec val alloc_reserve: #a:Type0 -> #rst:Type -> rg:regional rst a -> len:uint32_t{len > 0ul} -> rid:HST.erid -> HST.ST (rvector rg) (requires (fun h0 -> true)) (ensures (fun h0 rv h1 -> modifies (V.loc_vector rv) h0 h1 /\ rv_inv h1 rv /\ V.frameOf rv = rid /\ V.size_of rv = 0ul /\ S.equal (as_seq h1 rv) S.empty /\ Set.equal (Map.domain (HS.get_hmap h0)) (Map.domain (HS.get_hmap h1)) /\ B.fresh_loc (V.loc_vector rv) h0 h1)) let alloc_reserve #a #rst rg len rid = V.alloc_reserve len (rg_dummy rg) rid val alloc: #a:Type0 -> #rst:Type -> rg:regional rst a -> len:uint32_t{len > 0ul} -> HST.ST (rvector rg) (requires (fun h0 -> true)) (ensures (fun h0 rv h1 -> modifies (V.loc_vector rv) h0 h1 /\ rv_inv h1 rv /\ HS.fresh_region (V.frameOf rv) h0 h1 /\ V.size_of rv = len /\ V.forall_all h1 rv (fun r -> Rgl?.r_alloc_p rg r) /\ S.equal (as_seq h1 rv) (S.create (U32.v len) (Ghost.reveal (Rgl?.irepr rg))))) let alloc #a #rst rg len = let nrid = HST.new_region HS.root in alloc_rid rg len nrid val insert: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg{not (V.is_full rv)} -> v:a -> HST.ST (rvector rg) (requires (fun h0 -> rv_inv h0 rv /\ rg_inv rg h0 v /\ HS.extends (Rgl?.region_of rg v) (V.frameOf rv) /\ V.forall_all h0 rv (fun b -> HS.disjoint (Rgl?.region_of rg b) (Rgl?.region_of rg v)))) (ensures (fun h0 irv h1 -> V.size_of irv = V.size_of rv + 1ul /\ V.frameOf rv = V.frameOf irv /\ modifies (loc_union (V.loc_addr_of_vector rv) (V.loc_vector irv)) h0 h1 /\ rv_inv h1 irv /\ V.get h1 irv (V.size_of rv) == v /\ S.equal (as_seq h1 irv) (S.snoc (as_seq h0 rv) (Rgl?.r_repr rg h0 v)))) #reset-options "--z3rlimit 20" let insert #a #rst #rg rv v = let hh0 = HST.get () in let irv = V.insert rv v in let hh1 = HST.get () in // Safety rs_loc_elems_parent_disj rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)); rs_elems_inv_preserved rg (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv)) (loc_region_only false (V.frameOf rv)) hh0 hh1; Rgl?.r_sep rg v (loc_region_only false (V.frameOf rv)) hh0 hh1; // Correctness assert (S.equal (V.as_seq hh0 rv) (S.slice (V.as_seq hh1 irv) 0 (U32.v (V.size_of rv)))); as_seq_seq_preserved rg (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv)) (loc_region_only false (V.frameOf rv)) hh0 hh1; as_seq_seq_slice rg hh1 (V.as_seq hh1 irv) 0 (U32.v (V.size_of irv)) 0 (U32.v (V.size_of rv)); irv val insert_copy: #a:Type0 -> #rst:Type -> #rg:regional rst a -> cp:copyable #rst a rg -> rv:rvector rg{not (V.is_full rv)} -> v:a -> HST.ST (rvector rg) (requires (fun h0 -> rv_inv h0 rv /\ rg_inv rg h0 v /\ HS.disjoint (Rgl?.region_of rg v) (V.frameOf rv))) (ensures (fun h0 irv h1 -> V.size_of irv = V.size_of rv + 1ul /\ V.frameOf rv = V.frameOf irv /\ modifies (loc_rvector rv) h0 h1 /\ rv_inv h1 irv /\ S.equal (as_seq h1 irv) (S.snoc (as_seq h0 rv) (Rgl?.r_repr rg h0 v)))) let insert_copy #a #rst #rg cp rv v = let hh0 = HST.get () in rv_elems_inv_live_region hh0 rv 0ul (V.size_of rv); let nrid = HST.new_region (V.frameOf rv) in let nv = rg_alloc rg nrid in let hh1 = HST.get () in Rgl?.r_sep rg v loc_none hh0 hh1; rv_inv_preserved rv loc_none hh0 hh1; as_seq_preserved rv loc_none hh0 hh1; Cpy?.copy cp (Rgl?.state rg) v nv; let hh2 = HST.get () in rv_loc_elems_each_disj hh2 rv 0ul (V.size_of rv) nrid; rv_inv_preserved_ rv (loc_all_regions_from false nrid) hh1 hh2; as_seq_preserved_ rv (loc_all_regions_from false nrid) hh1 hh2; insert rv nv val assign: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t{i < V.size_of rv} -> v:a -> HST.ST unit (requires (fun h0 -> // rv_inv h0 rv /\ rv_itself_inv h0 rv /\ rv_elems_inv h0 rv 0ul i /\ rv_elems_inv h0 rv (i + 1ul) (V.size_of rv) /\ elems_reg h0 rv /\ V.forall_ h0 rv 0ul i (fun b -> HS.disjoint (Rgl?.region_of rg b) (Rgl?.region_of rg v)) /\ V.forall_ h0 rv (i + 1ul) (V.size_of rv) (fun b -> HS.disjoint (Rgl?.region_of rg b) (Rgl?.region_of rg v)) /\ rg_inv rg h0 v /\ HS.extends (Rgl?.region_of rg v) (V.frameOf rv))) (ensures (fun h0 _ h1 -> modifies (V.loc_vector_within rv i (i + 1ul)) h0 h1 /\ rv_inv h1 rv /\ V.get h1 rv i == v /\ S.equal (as_seq h1 rv) (S.append (as_seq_sub h0 rv 0ul i) (S.cons (Rgl?.r_repr rg h0 v) (as_seq_sub h0 rv (i + 1ul) (V.size_of rv)))))) let assign #a #rst #rg rv i v = let hh0 = HST.get () in V.assign rv i v; let hh1 = HST.get () in // Safety rs_loc_elems_parent_disj rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v i); rs_loc_elems_parent_disj rg (V.as_seq hh0 rv) (V.frameOf rv) (U32.v i + 1) (U32.v (V.size_of rv)); rs_elems_inv_preserved rg (V.as_seq hh0 rv) 0 (U32.v i) (V.loc_vector rv) hh0 hh1; rs_elems_inv_preserved rg (V.as_seq hh0 rv) (U32.v i + 1) (U32.v (V.size_of rv)) (V.loc_vector rv) hh0 hh1; Rgl?.r_sep rg v (V.loc_vector rv) hh0 hh1; // Correctness rs_loc_elems_parent_disj rg (V.as_seq hh1 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)); as_seq_seq_preserved rg (V.as_seq hh1 rv) 0 (U32.v (V.size_of rv)) (V.loc_vector rv) hh0 hh1 private val r_sep_forall: #a:Type0 -> #rst:Type -> rg:regional rst a -> p:loc -> h0:HS.mem -> h1:HS.mem -> v:a{rg_inv rg h0 v} -> Lemma (requires (loc_disjoint (loc_all_regions_from false (Rgl?.region_of rg v)) p /\ modifies p h0 h1)) (ensures (rg_inv rg h1 v /\ Rgl?.r_repr rg h0 v == Rgl?.r_repr rg h1 v)) private let r_sep_forall #a #rst rg p h0 h1 v = Rgl?.r_sep rg v p h0 h1 val assign_copy: #a:Type0 -> #rst:Type -> #rg:regional rst a -> cp:copyable #rst a rg -> rv:rvector rg -> i:uint32_t{i < V.size_of rv} -> v:a -> HST.ST unit (requires (fun h0 -> rv_inv h0 rv /\ rg_inv rg h0 v /\ HS.disjoint (Rgl?.region_of rg v) (V.frameOf rv))) (ensures (fun h0 _ h1 -> modifies (loc_all_regions_from false (Rgl?.region_of rg (V.get h1 rv i))) h0 h1 /\ rv_inv h1 rv /\ S.equal (as_seq h1 rv) (S.upd (as_seq h0 rv) (U32.v i) (Rgl?.r_repr rg h0 v)))) let assign_copy #a #rst #rg cp rv i v = let hh0 = HST.get () in Cpy?.copy cp (Rgl?.state rg) v (V.index rv i); let hh1 = HST.get () in // Safety rv_inv_preserved_int #a #rst #rg rv i hh0 hh1; // Correctness forall_intro (move_requires (rs_loc_elem_disj rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)) (U32.v i))); assert (forall (k:nat{k <> U32.v i && k < U32.v (V.size_of rv)}). loc_disjoint (rs_loc_elem rg (V.as_seq hh0 rv) k) (rs_loc_elem rg (V.as_seq hh0 rv) (U32.v i))); forall_intro (move_requires (r_sep_forall rg (rs_loc_elem rg (V.as_seq hh0 rv) (U32.v i)) hh0 hh1)); assert (forall (k:nat{k <> U32.v i && k < U32.v (V.size_of rv)}). loc_disjoint (rs_loc_elem rg (V.as_seq hh0 rv) k) (rs_loc_elem rg (V.as_seq hh0 rv) (U32.v i)) ==> Rgl?.r_repr rg hh1 (S.index (V.as_seq hh1 rv) k) == Rgl?.r_repr rg hh0 (S.index (V.as_seq hh0 rv) k)); assert (forall (k:nat{k <> U32.v i && k < U32.v (V.size_of rv)}). Rgl?.r_repr rg hh1 (S.index (V.as_seq hh1 rv) k) == Rgl?.r_repr rg hh0 (S.index (V.as_seq hh0 rv) k)); assert (forall (k:nat{k <> U32.v i && k < U32.v (V.size_of rv)}). S.index (as_seq_seq rg hh1 (V.as_seq hh1 rv) 0 (U32.v (V.size_of rv))) k == S.index (as_seq_seq rg hh0 (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv))) k) val free_elems: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> idx:uint32_t{idx < V.size_of rv} -> HST.ST unit (requires (fun h0 -> V.live h0 rv /\ rv_elems_inv h0 rv 0ul (idx + 1ul) /\ rv_elems_reg h0 rv 0ul (idx + 1ul))) (ensures (fun h0 _ h1 -> modifies (rv_loc_elems h0 rv 0ul (idx + 1ul)) h0 h1)) let rec free_elems #a #rst #rg rv idx = let hh0 = HST.get () in rg_free rg (V.index rv idx); let hh1 = HST.get () in rs_loc_elems_elem_disj rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v idx + 1) 0 (U32.v idx) (U32.v idx); rv_elems_inv_preserved rv 0ul idx (rs_loc_elem rg (V.as_seq hh0 rv) (U32.v idx)) hh0 hh1; if idx <> 0ul then free_elems rv (idx - 1ul) val flush: #a:Type0 -> #rst:Type -> #rg:regional rst a -> rv:rvector rg -> i:uint32_t{i <= V.size_of rv} -> HST.ST (rvector rg) (requires (fun h0 -> rv_inv h0 rv)) (ensures (fun h0 frv h1 -> V.size_of frv = V.size_of rv - i /\ V.frameOf rv = V.frameOf frv /\ modifies (loc_rvector rv) h0 h1 /\ rv_inv h1 frv /\ S.equal (as_seq h1 frv) (S.slice (as_seq h0 rv) (U32.v i) (U32.v (V.size_of rv)))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Vector.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.RVector.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rv: LowStar.RVector.rvector rg -> i: LowStar.Vector.uint32_t{i <= LowStar.Vector.size_of rv} -> FStar.HyperStack.ST.ST (LowStar.RVector.rvector rg)
FStar.HyperStack.ST.ST
[]
[]
[ "LowStar.Regional.regional", "LowStar.RVector.rvector", "LowStar.Vector.uint32_t", "Prims.b2t", "FStar.Integers.op_Less_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Vector.size_of", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "LowStar.Regional.__proj__Rgl__item__repr", "FStar.Seq.Base.slice", "LowStar.RVector.as_seq", "FStar.UInt32.v", "LowStar.RVector.as_seq_seq", "LowStar.Vector.as_seq", "LowStar.RVector.as_seq_seq_eq", "LowStar.RVector.as_seq_seq_slice", "LowStar.RVector.as_seq_seq_preserved", "LowStar.Monotonic.Buffer.loc_union", "LowStar.RVector.rs_loc_elems", "LowStar.Monotonic.Buffer.loc_region_only", "LowStar.Vector.frameOf", "LowStar.RVector.rv_inv", "LowStar.RVector.rs_elems_inv_preserved", "LowStar.RVector.rs_loc_elems_parent_disj", "LowStar.RVector.rs_loc_elems_disj", "LowStar.Monotonic.Buffer.modifies", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Vector.vector", "LowStar.Vector.flush", "LowStar.Regional.rg_dummy", "LowStar.RVector.rv_loc_elems_included", "FStar.UInt32.__uint_to_t", "Prims.op_Equality", "FStar.UInt32.t", "Prims.bool", "LowStar.RVector.free_elems", "FStar.Integers.op_Subtraction" ]
[]
false
true
false
false
false
let flush #a #rst #rg rv i =
let hh0 = HST.get () in (if i = 0ul then () else free_elems rv (i - 1ul)); rv_loc_elems_included hh0 rv 0ul i; let hh1 = HST.get () in assert (modifies (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) hh0 hh1); let frv = V.flush rv (rg_dummy rg) i in let hh2 = HST.get () in assert (modifies (loc_region_only false (V.frameOf rv)) hh1 hh2); rs_loc_elems_disj rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv)) 0 (U32.v i) (U32.v i) (U32.v (V.size_of rv)); rs_loc_elems_parent_disj rg (V.as_seq hh0 rv) (V.frameOf rv) (U32.v i) (U32.v (V.size_of rv)); rs_elems_inv_preserved rg (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)) (loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) (loc_region_only false (V.frameOf rv))) hh0 hh2; assert (rv_inv #a #rst #rg hh2 frv); as_seq_seq_preserved rg (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)) (loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) (loc_region_only false (V.frameOf rv))) hh0 hh2; as_seq_seq_slice rg hh0 (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv)) (U32.v i) (U32.v (V.size_of rv)); assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))) (as_seq_seq rg hh2 (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))); as_seq_seq_eq rg hh2 (V.as_seq hh0 rv) (V.as_seq hh2 frv) (U32.v i) (U32.v (V.size_of rv)) 0 (U32.v (V.size_of frv)); assert (S.equal (as_seq_seq rg hh2 (V.as_seq hh2 frv) 0 (U32.v (V.size_of frv))) (as_seq_seq rg hh2 (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))); assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))) (as_seq hh2 frv)); frv
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_insert
val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt})
let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 22, "end_line": 241, "start_col": 0, "start_line": 234 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree {MerkleTree.New.High.mt_wf_elts mt /\ MerkleTree.New.High.mt_not_full mt} -> v: MerkleTree.New.High.hash -> Prims.GTot (imt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts imt})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "Prims.l_and", "MerkleTree.New.High.mt_wf_elts", "Prims.b2t", "MerkleTree.New.High.mt_not_full", "MerkleTree.New.High.hash", "MerkleTree.New.High.MT", "MerkleTree.New.High.__proj__MT__item__i", "Prims.op_Addition", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.insert_", "MerkleTree.New.High.__proj__MT__item__hash_fun", "MerkleTree.New.High.__proj__MT__item__hs", "MerkleTree.New.High.__proj__MT__item__rhs", "MerkleTree.New.High.__proj__MT__item__mroot" ]
[]
false
false
false
false
false
let mt_insert #hsz mt v =
MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
false
MerkleTree.New.High.fst
MerkleTree.New.High.create_empty_mt
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt})
let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 86, "end_line": 156, "start_col": 0, "start_line": 154 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Prims.GTot (mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.unit", "MerkleTree.New.High.MT", "FStar.Seq.Base.create", "MerkleTree.New.High.hashes", "FStar.Seq.Base.empty", "MerkleTree.New.High.hash", "MerkleTree.New.High.hash_init", "MerkleTree.New.High.hs_wf_elts_empty", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts" ]
[]
false
false
false
false
false
let create_empty_mt #hsz #f _ =
hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f
false
MerkleTree.New.High.fst
MerkleTree.New.High.seq_slice_equal_index
val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)]
val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)]
let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 79, "end_line": 41, "start_col": 0, "start_line": 40 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j));
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s1 && j <= FStar.Seq.Base.length s2} -> k: Prims.nat{i <= k && k < j} -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 i j) (FStar.Seq.Base.slice s2 i j)) (ensures FStar.Seq.Base.index s1 k == FStar.Seq.Base.index s2 k) [ SMTPat (FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 i j) (FStar.Seq.Base.slice s2 i j)); SMTPat (FStar.Seq.Base.index s1 k) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "Prims.b2t", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "Prims.op_LessThan", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "Prims.unit" ]
[]
true
false
true
false
false
let seq_slice_equal_index #a s1 s2 i j k =
assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i))
false
MerkleTree.New.High.fst
MerkleTree.New.High.hs_wf_elts
val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv))
val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv))
let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 51, "end_line": 108, "start_col": 0, "start_line": 104 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> i: Prims.nat -> j: Prims.nat{j >= i} -> Prims.GTot Type0
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.op_GreaterThanOrEqual", "Prims.bool", "Prims.l_and", "Prims.eq2", "MerkleTree.New.High.hash", "FStar.Seq.Base.index", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_Addition", "Prims.op_Division", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
false
false
true
let rec hs_wf_elts #hsz lv hs i j =
if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2))
false
OneTimePad.fst
OneTimePad.related_tape
val related_tape : b: (_: Prims.int -> Bijection.bij) -> t_0: OneTimePad.tape -> t_1: OneTimePad.tape -> Prims.logical
let related_tape (b:int -> bij) (t_0 t_1:tape) = forall i. b i (t_0 i) = (t_1 i)
{ "file_name": "examples/rel/OneTimePad.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 80, "end_line": 59, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module OneTimePad open Bijection #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0 --initial_ifuel 4 --max_ifuel 4" let nib = bool * bool * bool * bool let xor_b (b1:bool) (b2:bool) = b1 <> b2 let xor (a, b, c, d) (w, x, y, z) = (a `xor_b` w, b `xor_b` x, c `xor_b` y, d `xor_b` z) let xor_properties (x:nib) (y:nib) = assert (x `xor` y = y `xor` x); assert (y `xor` (x `xor` y) = x); assert (x `xor` (x `xor` y) = y); assert ((x `xor` y) `xor` y = x) type tape = int -> Tot nib type random (a:Type) = (int * (int -> Tot nib)) -> M (a * int) let return (a:Type) (x:a) : random a = fun s -> (x, fst s) let bind (a b : Type) (x:random a) (f: a -> random b) : random b = fun store -> let (z, n) = x store in f z (n, snd store) let rand () : random nib = fun store -> let n, tape = store in tape n, n + 1 total reifiable reflectable new_effect { RANDOM : a:Type -> Effect with repr = random ; bind = bind ; return = return ; rand = rand } effect Rand (a:Type) = RANDOM a (fun initial_tape post -> forall (x:(a * int)). post x) let one_time_pad () : Rand ((nib -> nib) * (nib -> nib)) = let key = RANDOM?.rand () in let encrypt (msg:nib) = msg `xor` key in let decrypt (cipher:nib) = cipher `xor` key in encrypt, decrypt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "Bijection.fst.checked" ], "interface_file": false, "source_file": "OneTimePad.fst" }
[ { "abbrev": false, "full_module": "Bijection", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 4, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: (_: Prims.int -> Bijection.bij) -> t_0: OneTimePad.tape -> t_1: OneTimePad.tape -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Bijection.bij", "OneTimePad.nib", "OneTimePad.tape", "Prims.l_Forall", "Prims.b2t", "Prims.op_Equality", "Prims.logical" ]
[]
false
false
false
true
true
let related_tape (b: (int -> bij)) (t_0 t_1: tape) =
forall i. b i (t_0 i) = (t_1 i)
false
MerkleTree.New.High.fst
MerkleTree.New.High.hs_wf_elts_equal
val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv))
val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv))
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 57, "end_line": 132, "start_col": 0, "start_line": 123 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j)
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs1: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs1 = 32} -> hs2: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs2 = 32} -> i: Prims.nat -> j: Prims.nat{j >= i} -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.hs_wf_elts lv hs1 i j /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice hs1 lv 32) (FStar.Seq.Base.slice hs2 lv 32)) (ensures MerkleTree.New.High.hs_wf_elts lv hs2 i j) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.op_GreaterThanOrEqual", "Prims.bool", "MerkleTree.New.High.hs_wf_elts_equal", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index", "FStar.Seq.Base.lemma_index_slice", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Seq.Properties.slice_slice", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
true
false
false
let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j =
if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2))
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_create
val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt})
let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 46, "end_line": 247, "start_col": 0, "start_line": 246 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hsz: Prims.pos -> f: MerkleTree.Spec.hash_fun_t -> init: MerkleTree.New.High.hash -> Prims.GTot (mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "MerkleTree.New.High.hash", "MerkleTree.New.High.mt_insert", "MerkleTree.New.High.create_empty_mt", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts" ]
[]
false
false
false
false
false
let mt_create hsz f init =
mt_insert #_ (create_empty_mt #_ #f ()) init
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.qmont_cancel_lemma1
val qmont_cancel_lemma1: a:S.qelem -> b:S.qelem -> Lemma ((a * qmont_R % S.order * b * qmont_R_inv) % S.order = a * b % S.order)
val qmont_cancel_lemma1: a:S.qelem -> b:S.qelem -> Lemma ((a * qmont_R % S.order * b * qmont_R_inv) % S.order = a * b % S.order)
let qmont_cancel_lemma1 a b = mul_qmont_R_and_R_inv_is_one (); mont_cancel_lemma_gen S.order qmont_R qmont_R_inv a b
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 318, "start_col": 0, "start_line": 316 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //-------------------------- let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a let lemma_from_to_qmont_id a = mul_qmont_R_and_R_inv_is_one (); Math.Lemmas.swap_mul qmont_R qmont_R_inv; lemma_from_to_mont_id_gen S.order qmont_R qmont_R_inv a let qmont_add_lemma a b = mont_add_lemma_gen S.order qmont_R_inv a b let qmont_mul_lemma a b = mont_mul_lemma_gen S.order qmont_R_inv a b let qmont_inv_lemma k = assert_norm (M.pow_mod_ #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); M.pow_mod_def #S.order qmont_R_inv (S.order - 2); assert (M.pow_mod #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); lemma_mont_inv_gen S.order qmont_R qmont_R_inv k; assert (M.pow_mod #S.order (k * qmont_R_inv % S.order) (S.order - 2) == M.pow_mod #S.order k (S.order - 2) * qmont_R % S.order); assert (S.qinv (k * qmont_R_inv % S.order) == S.qinv k * qmont_R % S.order) val qmont_cancel_lemma1: a:S.qelem -> b:S.qelem -> Lemma ((a * qmont_R % S.order * b * qmont_R_inv) % S.order = a * b % S.order)
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.P256.PointOps.qelem -> b: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures ((a * Hacl.Spec.P256.Montgomery.qmont_R % Spec.P256.PointOps.order) * b) * Hacl.Spec.P256.Montgomery.qmont_R_inv % Spec.P256.PointOps.order = a * b % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Hacl.Spec.P256.Montgomery.mont_cancel_lemma_gen", "Spec.P256.PointOps.order", "Hacl.Spec.P256.Montgomery.qmont_R", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Prims.unit", "Hacl.Spec.P256.Montgomery.mul_qmont_R_and_R_inv_is_one" ]
[]
true
false
true
false
false
let qmont_cancel_lemma1 a b =
mul_qmont_R_and_R_inv_is_one (); mont_cancel_lemma_gen S.order qmont_R qmont_R_inv a b
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.qmont_inv_lemma
val qmont_inv_lemma: k:S.qelem -> Lemma (S.qinv (from_qmont k) == to_qmont (S.qinv k))
val qmont_inv_lemma: k:S.qelem -> Lemma (S.qinv (from_qmont k) == to_qmont (S.qinv k))
let qmont_inv_lemma k = assert_norm (M.pow_mod_ #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); M.pow_mod_def #S.order qmont_R_inv (S.order - 2); assert (M.pow_mod #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); lemma_mont_inv_gen S.order qmont_R qmont_R_inv k; assert (M.pow_mod #S.order (k * qmont_R_inv % S.order) (S.order - 2) == M.pow_mod #S.order k (S.order - 2) * qmont_R % S.order); assert (S.qinv (k * qmont_R_inv % S.order) == S.qinv k * qmont_R % S.order)
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 310, "start_col": 0, "start_line": 302 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //-------------------------- let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a let lemma_from_to_qmont_id a = mul_qmont_R_and_R_inv_is_one (); Math.Lemmas.swap_mul qmont_R qmont_R_inv; lemma_from_to_mont_id_gen S.order qmont_R qmont_R_inv a let qmont_add_lemma a b = mont_add_lemma_gen S.order qmont_R_inv a b let qmont_mul_lemma a b = mont_mul_lemma_gen S.order qmont_R_inv a b
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures Spec.P256.PointOps.qinv (Hacl.Spec.P256.Montgomery.from_qmont k) == Hacl.Spec.P256.Montgomery.to_qmont (Spec.P256.PointOps.qinv k))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims._assert", "Prims.eq2", "Prims.int", "Spec.P256.PointOps.qinv", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Spec.P256.PointOps.order", "Hacl.Spec.P256.Montgomery.qmont_R", "Prims.unit", "Lib.NatMod.pow_mod", "Prims.op_Subtraction", "Hacl.Spec.P256.Montgomery.lemma_mont_inv_gen", "Lib.NatMod.pow_mod_def", "FStar.Pervasives.assert_norm", "Lib.NatMod.pow_mod_" ]
[]
true
false
true
false
false
let qmont_inv_lemma k =
assert_norm (M.pow_mod_ #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); M.pow_mod_def #S.order qmont_R_inv (S.order - 2); assert (M.pow_mod #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); lemma_mont_inv_gen S.order qmont_R qmont_R_inv k; assert (M.pow_mod #S.order (k * qmont_R_inv % S.order) (S.order - 2) == M.pow_mod #S.order k (S.order - 2) * qmont_R % S.order); assert (S.qinv (k * qmont_R_inv % S.order) == S.qinv k * qmont_R % S.order)
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_get_root
val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz)
val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz)
let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 358, "start_col": 0, "start_line": 353 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} -> drt: MerkleTree.New.High.hash -> Prims.GTot (MerkleTree.New.High.merkle_tree * MerkleTree.New.High.hash)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts", "MerkleTree.New.High.hash", "MerkleTree.New.High.__proj__MT__item__rhs_ok", "FStar.Pervasives.Native.Mktuple2", "MerkleTree.New.High.__proj__MT__item__mroot", "Prims.bool", "MerkleTree.New.High.hashes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.MT", "MerkleTree.New.High.__proj__MT__item__i", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.__proj__MT__item__hs", "MerkleTree.New.High.__proj__MT__item__hash_fun", "FStar.Pervasives.Native.tuple2", "MerkleTree.New.High.construct_rhs", "MerkleTree.New.High.__proj__MT__item__rhs" ]
[]
false
false
false
false
false
let mt_get_root #hsz mt drt =
if MT?.rhs_ok mt then (mt, MT?.mroot mt) else let nrhs, rt = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt)
false
MerkleTree.New.High.fst
MerkleTree.New.High.hs_wf_elts_empty
val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv))
val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv))
let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 37, "end_line": 148, "start_col": 0, "start_line": 146 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0)
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> FStar.Pervasives.Lemma (ensures MerkleTree.New.High.hs_wf_elts lv (FStar.Seq.Base.create 32 FStar.Seq.Base.empty) 0 0 ) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Prims.bool", "MerkleTree.New.High.hs_wf_elts_empty", "Prims.op_Addition", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec hs_wf_elts_empty #hsz lv =
if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1)
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_path_length_step
val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 14, "end_line": 388, "start_col": 0, "start_line": 384 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step:
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Prims.nat -> j: Prims.nat{k <= j} -> actd: Prims.bool -> Prims.GTot Prims.nat
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.bool", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.op_BarBar", "Prims.op_AmpAmp", "Prims.op_Addition", "Prims.op_Negation" ]
[]
false
false
false
false
false
let mt_path_length_step k j actd =
if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1)
false
MerkleTree.New.High.fst
MerkleTree.New.High.hashess_insert
val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)})
let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 171, "start_col": 0, "start_line": 168 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) - 1} -> hs: MerkleTree.New.High.hashess {FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> v: MerkleTree.New.High.hash -> Prims.GTot (ihs: MerkleTree.New.High.hashess { FStar.Seq.Base.length ihs = 32 /\ MerkleTree.New.High.hs_wf_elts (lv + 1) ihs (i / 2) (j / 2) })
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hs_wf_elts", "MerkleTree.New.High.hash", "Prims.unit", "MerkleTree.New.High.hs_wf_elts_equal", "Prims.op_Addition", "Prims.op_Division", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "FStar.Seq.Properties.snoc", "FStar.Seq.Base.index" ]
[]
false
false
false
false
false
let hashess_insert #hsz lv i j hs v =
let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_path_length
val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat
let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 44, "end_line": 396, "start_col": 0, "start_line": 392 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length:
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Prims.nat -> j: Prims.nat{k <= j} -> actd: Prims.bool -> Prims.GTot Prims.nat
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.bool", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "MerkleTree.New.High.mt_path_length_step", "MerkleTree.New.High.mt_path_length", "Prims.op_Division", "Prims.op_BarBar", "Prims.op_Modulus" ]
[ "recursion" ]
false
false
false
false
false
let rec mt_path_length k j actd =
if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd)
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_flush
val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush #hsz mt = mt_flush_to mt (MT?.j mt - 1)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 31, "end_line": 598, "start_col": 0, "start_line": 597 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i) let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) val mt_flush_to_rec: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs pi j} -> Lemma (requires offset_of i <> offset_of pi) (ensures mt_flush_to_ lv hs pi i j == (let ofs = offset_of i - offset_of pi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2))) let mt_flush_to_rec #hsz lv hs pi i j = () val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush_to #hsz mt idx = let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> Prims.GTot (fmt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts fmt})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "Prims.l_and", "MerkleTree.New.High.mt_wf_elts", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.__proj__MT__item__i", "MerkleTree.New.High.mt_flush_to", "Prims.op_Subtraction" ]
[]
false
false
false
false
false
let mt_flush #hsz mt =
mt_flush_to mt (MT?.j mt - 1)
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_retract_to
val mt_retract_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> r:nat{MT?.i mt <= r /\ r < MT?.j mt} -> GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1})
val mt_retract_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> r:nat{MT?.i mt <= r /\ r < MT?.j mt} -> GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1})
let mt_retract_to #hsz mt r = let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r+1) (MT?.j mt) in MT (MT?.i mt) (r+1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 77, "end_line": 645, "start_col": 0, "start_line": 643 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i) let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) val mt_flush_to_rec: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs pi j} -> Lemma (requires offset_of i <> offset_of pi) (ensures mt_flush_to_ lv hs pi i j == (let ofs = offset_of i - offset_of pi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2))) let mt_flush_to_rec #hsz lv hs pi i j = () val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush_to #hsz mt idx = let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush #hsz mt = mt_flush_to mt (MT?.j mt - 1) #push-options "--max_fuel 2" /// Retraction val mt_retract_to_: #hsz:pos -> hs:hashess #hsz {S.length hs = 32} -> lv:nat{lv < S.length hs} -> i:nat -> s:nat -> // s is the first index excluded from nhs j:nat{ i <= s /\ s <= j /\ j < pow2 (S.length hs - lv) /\ hs_wf_elts lv hs i j} -> GTot (nhs:hashess #hsz { S.length nhs = S.length hs /\ S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\ hs_wf_elts #hsz lv nhs i s}) (decreases (S.length hs - lv)) let rec mt_retract_to_ #hsz hs lv i s j = if lv >= S.length hs then hs else begin let hvec = S.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in assert (S.length hvec = old_len); assert (new_len <= old_len); assert (new_len <= S.length hvec); let retracted = S.slice hvec 0 new_len in let nhs = S.upd hs lv retracted in if lv >= S.length hs - 1 then nhs else begin hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2); mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2) end end #pop-options val mt_retract_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> r:nat{MT?.i mt <= r /\ r < MT?.j mt} ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} -> r: Prims.nat{MT?.i mt <= r /\ r < MT?.j mt} -> Prims.GTot (rmt: MerkleTree.New.High.merkle_tree {MerkleTree.New.High.mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.__proj__MT__item__i", "Prims.op_LessThan", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.MT", "Prims.op_Addition", "MerkleTree.New.High.__proj__MT__item__rhs", "MerkleTree.New.High.__proj__MT__item__mroot", "MerkleTree.New.High.__proj__MT__item__hash_fun", "MerkleTree.New.High.hashess", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.__proj__MT__item__hs", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "MerkleTree.New.High.hs_wf_elts", "MerkleTree.New.High.mt_retract_to_", "Prims.int" ]
[]
false
false
false
false
false
let mt_retract_to #hsz mt r =
let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r + 1) (MT?.j mt) in MT (MT?.i mt) (r + 1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_make_path_step
val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz)
val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz)
let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 64, "end_line": 420, "start_col": 0, "start_line": 411 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat {j <> 0 /\ i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> k: Prims.nat{i <= k && k <= j} -> p: MerkleTree.New.High.path -> actd: Prims.bool -> Prims.GTot MerkleTree.New.High.path
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_disEquality", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_AmpAmp", "MerkleTree.New.High.path", "Prims.bool", "Prims.op_Modulus", "MerkleTree.New.High.path_insert", "FStar.Seq.Base.index", "Prims.l_or", "Prims.op_Addition", "MerkleTree.New.High.offset_of" ]
[]
false
false
false
false
false
let mt_make_path_step #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs)))
false
MerkleTree.New.High.fst
MerkleTree.New.High.construct_rhs
val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j)
val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j)
let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 73, "end_line": 279, "start_col": 0, "start_line": 269 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> Prims.GTot (crhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length crhs = 32} * MerkleTree.New.High.hash)
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.bool", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Modulus", "MerkleTree.New.High.construct_rhs", "Prims.op_Addition", "Prims.op_Division", "FStar.Seq.Base.index", "FStar.Seq.Base.upd", "FStar.Pervasives.Native.tuple2", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
false
false
false
let rec construct_rhs #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true))
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_flush_to
val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt})
let mt_flush_to #hsz mt idx = let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 85, "end_line": 591, "start_col": 0, "start_line": 589 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i) let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) val mt_flush_to_rec: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs pi j} -> Lemma (requires offset_of i <> offset_of pi) (ensures mt_flush_to_ lv hs pi i j == (let ofs = offset_of i - offset_of pi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2))) let mt_flush_to_rec #hsz lv hs pi i j = () val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} -> idx: Prims.nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> Prims.GTot (fmt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts fmt})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "MerkleTree.New.High.__proj__MT__item__i", "Prims.op_LessThan", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.MT", "MerkleTree.New.High.__proj__MT__item__rhs_ok", "MerkleTree.New.High.__proj__MT__item__rhs", "MerkleTree.New.High.__proj__MT__item__mroot", "MerkleTree.New.High.__proj__MT__item__hash_fun", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "MerkleTree.New.High.__proj__MT__item__hs", "MerkleTree.New.High.hs_wf_elts", "MerkleTree.New.High.mt_flush_to_" ]
[]
false
false
false
false
false
let mt_flush_to #hsz mt idx =
let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt)
false
Hacl.K256.PrecompTable.fst
Hacl.K256.PrecompTable.precomp_g_pow2_64_table_w4
val precomp_g_pow2_64_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x}
val precomp_g_pow2_64_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x}
let precomp_g_pow2_64_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x} = createL_global precomp_g_pow2_64_table_list_w4
{ "file_name": "code/k256/Hacl.K256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 234, "start_col": 0, "start_line": 232 }
module Hacl.K256.PrecompTable open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module SPT = Hacl.Spec.PrecompBaseTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module SPTK = Hacl.Spec.K256.PrecompTable module S = Spec.K256 module SL = Spec.K256.Lemmas open Hacl.Impl.K256.Point include Hacl.Impl.K256.Group #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let proj_point_to_list p = SPTK.proj_point_to_list_lemma p; SPTK.proj_point_to_list p let lemma_refl x = SPTK.proj_point_to_list_lemma x //----------------- inline_for_extraction noextract let proj_g_pow2_64 : S.proj_point = [@inline_let] let rX : S.felem = 0x46ec0aa60b0b98c37b29371784676ad967b7beb1a941ddb6fbbff95b44cb788b in [@inline_let] let rY : S.felem = 0x6b946755bbc6b677576579c990a1ccf14a710545251a1428fabbf02f40268e63 in [@inline_let] let rZ : S.felem = 0x3c114b2ac17c199ec9eba9f7cc64dc459ca2e53f5bbead2b4e618b318ffcc00e in (rX, rY, rZ) val lemma_proj_g_pow2_64_eval : unit -> Lemma (SE.exp_pow2 S.mk_k256_concrete_ops S.g 64 == proj_g_pow2_64) let lemma_proj_g_pow2_64_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops S.g 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64); let rX : S.felem = 0x46ec0aa60b0b98c37b29371784676ad967b7beb1a941ddb6fbbff95b44cb788b in let rY : S.felem = 0x6b946755bbc6b677576579c990a1ccf14a710545251a1428fabbf02f40268e63 in let rZ : S.felem = 0x3c114b2ac17c199ec9eba9f7cc64dc459ca2e53f5bbead2b4e618b318ffcc00e in assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) inline_for_extraction noextract let proj_g_pow2_128 : S.proj_point = [@inline_let] let rX : S.felem = 0x98299efbc8e459915404ae015b48cac3b929e0158665f3c7fa5489fbd25c4297 in [@inline_let] let rY : S.felem = 0xf1e5cbc9579e7d11a31681e947c2959ae0298a006d1c06ab1ad93d6716ea50cc in [@inline_let] let rZ : S.felem = 0x5c53ffe15001674a2eacb60c9327a8b0ddbd93a0fa6d90309de6cc124133938b in (rX, rY, rZ) val lemma_proj_g_pow2_128_eval : unit -> Lemma (SE.exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128) let lemma_proj_g_pow2_128_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_64 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64); let rX : S.felem = 0x98299efbc8e459915404ae015b48cac3b929e0158665f3c7fa5489fbd25c4297 in let rY : S.felem = 0xf1e5cbc9579e7d11a31681e947c2959ae0298a006d1c06ab1ad93d6716ea50cc in let rZ : S.felem = 0x5c53ffe15001674a2eacb60c9327a8b0ddbd93a0fa6d90309de6cc124133938b in assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) inline_for_extraction noextract let proj_g_pow2_192 : S.proj_point = [@inline_let] let rX : S.felem = 0xbd382b67d20492b1480ca58a6d7d617ba413a9bc7c2f1cff51301ef960fb245c in [@inline_let] let rY : S.felem = 0x0b232afcf692673aa714357c524c07867a64ea3b9dfab53f0e74622159e86b0d in [@inline_let] let rZ : S.felem = 0x028a1380449aede5df8219420b458d464a6a4773ac91e8305237878cef1cffa6 in (rX, rY, rZ) val lemma_proj_g_pow2_192_eval : unit -> Lemma (SE.exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192) let lemma_proj_g_pow2_192_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_128 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64); let rX : S.felem = 0xbd382b67d20492b1480ca58a6d7d617ba413a9bc7c2f1cff51301ef960fb245c in let rY : S.felem = 0x0b232afcf692673aa714357c524c07867a64ea3b9dfab53f0e74622159e86b0d in let rZ : S.felem = 0x028a1380449aede5df8219420b458d464a6a4773ac91e8305237878cef1cffa6 in assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) // let proj_g_pow2_64 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64) // let proj_g_pow2_128 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64) // let proj_g_pow2_192 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64) inline_for_extraction noextract let proj_g_pow2_64_list : SPTK.point_list = normalize_term (SPTK.proj_point_to_list proj_g_pow2_64) inline_for_extraction noextract let proj_g_pow2_128_list : SPTK.point_list = normalize_term (SPTK.proj_point_to_list proj_g_pow2_128) inline_for_extraction noextract let proj_g_pow2_192_list : SPTK.point_list = normalize_term (SPTK.proj_point_to_list proj_g_pow2_192) let proj_g_pow2_64_lseq : LSeq.lseq uint64 15 = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64); Seq.seq_of_list proj_g_pow2_64_list let proj_g_pow2_128_lseq : LSeq.lseq uint64 15 = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128); Seq.seq_of_list proj_g_pow2_128_list let proj_g_pow2_192_lseq : LSeq.lseq uint64 15 = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192); Seq.seq_of_list proj_g_pow2_192_list val proj_g_pow2_64_lemma: unit -> Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff) let proj_g_pow2_64_lemma () = lemma_proj_g_pow2_64_eval (); SPT256.a_pow2_64_lemma S.mk_k256_concrete_ops S.g val proj_g_pow2_128_lemma: unit -> Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff) let proj_g_pow2_128_lemma () = lemma_proj_g_pow2_128_eval (); lemma_proj_g_pow2_64_eval (); SPT256.a_pow2_128_lemma S.mk_k256_concrete_ops S.g val proj_g_pow2_192_lemma: unit -> Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff) let proj_g_pow2_192_lemma () = lemma_proj_g_pow2_192_eval (); lemma_proj_g_pow2_128_eval (); lemma_proj_g_pow2_64_eval (); SPT256.a_pow2_192_lemma S.mk_k256_concrete_ops S.g let proj_g_pow2_64_lseq_lemma () = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64); proj_g_pow2_64_lemma (); SPTK.proj_point_to_list_lemma proj_g_pow2_64 let proj_g_pow2_128_lseq_lemma () = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128); proj_g_pow2_128_lemma (); SPTK.proj_point_to_list_lemma proj_g_pow2_128 let proj_g_pow2_192_lseq_lemma () = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192); proj_g_pow2_192_lemma (); SPTK.proj_point_to_list_lemma proj_g_pow2_192 let mk_proj_g_pow2_64 () = createL proj_g_pow2_64_list let mk_proj_g_pow2_128 () = createL proj_g_pow2_128_list let mk_proj_g_pow2_192 () = createL proj_g_pow2_192_list //---------------- /// window size = 4; precomputed table = [[0]G, [1]G, ..., [15]G] inline_for_extraction noextract let precomp_basepoint_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} = normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15) let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 240 = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15); Seq.seq_of_list precomp_basepoint_table_list_w4 let precomp_basepoint_table_lemma_w4 () = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15); SPT.precomp_base_table_lemma mk_k256_precomp_base_table S.g 16 precomp_basepoint_table_lseq_w4 let precomp_basepoint_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} = createL_global precomp_basepoint_table_list_w4 /// window size = 4; precomputed table = [[0]([pow2 64]G), [1]([pow2 64]G), ..., [15]([pow2 64]G)] inline_for_extraction noextract let precomp_g_pow2_64_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} = normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15) let precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 240 = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15); Seq.seq_of_list precomp_g_pow2_64_table_list_w4 let precomp_g_pow2_64_table_lemma_w4 () = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15); SPT.precomp_base_table_lemma mk_k256_precomp_base_table proj_g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4; proj_g_pow2_64_lemma ()
{ "checked_file": "/", "dependencies": [ "Spec.K256.Lemmas.fsti.checked", "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.K256.PrecompTable.fsti.checked", "Hacl.Impl.K256.Point.fsti.checked", "Hacl.Impl.K256.Group.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.K256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Spec.K256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.PrecompTable", "short_module": "SPTK" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Impl.K256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256.Point", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.Buffer.glbuffer Lib.IntTypes.uint64 240ul { Lib.Buffer.witnessed x Hacl.K256.PrecompTable.precomp_g_pow2_64_table_lseq_w4 /\ Lib.Buffer.recallable x }
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.K256.PrecompTable.precomp_g_pow2_64_table_list_w4", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Prims.l_and", "Lib.Buffer.witnessed", "Hacl.K256.PrecompTable.precomp_g_pow2_64_table_lseq_w4", "Lib.Buffer.recallable", "Lib.Buffer.CONST" ]
[]
false
false
false
false
false
let precomp_g_pow2_64_table_w4:x: glbuffer uint64 240ul {witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x} =
createL_global precomp_g_pow2_64_table_list_w4
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_get_path_
val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv))
val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv))
let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 42, "end_line": 444, "start_col": 0, "start_line": 438 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd})
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> k: Prims.nat{i <= k && k <= j} -> p: MerkleTree.New.High.path -> actd: Prims.bool -> Prims.GTot (np: MerkleTree.New.High.path { FStar.Seq.Base.length np = FStar.Seq.Base.length p + MerkleTree.New.High.mt_path_length k j actd })
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_AmpAmp", "MerkleTree.New.High.path", "Prims.bool", "MerkleTree.New.High.mt_get_path_", "Prims.op_Addition", "Prims.op_Division", "Prims.op_Modulus", "Prims.precedes", "MerkleTree.New.High.mt_make_path_step", "MerkleTree.New.High.mt_path_length", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
false
false
false
let rec mt_get_path_ #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true))
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_verify
val mt_verify: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k < j} -> p:path #hsz {S.length p = 1 + mt_path_length k j false} -> rt:hash #hsz -> GTot prop
val mt_verify: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k < j} -> p:path #hsz {S.length p = 1 + mt_path_length k j false} -> rt:hash #hsz -> GTot prop
let mt_verify #_ #f k j p rt = let crt = mt_verify_ #_ #f k j p 1 (S.index p 0) false in crt == rt
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 11, "end_line": 679, "start_col": 0, "start_line": 677 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i) let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) val mt_flush_to_rec: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs pi j} -> Lemma (requires offset_of i <> offset_of pi) (ensures mt_flush_to_ lv hs pi i j == (let ofs = offset_of i - offset_of pi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2))) let mt_flush_to_rec #hsz lv hs pi i j = () val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush_to #hsz mt idx = let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush #hsz mt = mt_flush_to mt (MT?.j mt - 1) #push-options "--max_fuel 2" /// Retraction val mt_retract_to_: #hsz:pos -> hs:hashess #hsz {S.length hs = 32} -> lv:nat{lv < S.length hs} -> i:nat -> s:nat -> // s is the first index excluded from nhs j:nat{ i <= s /\ s <= j /\ j < pow2 (S.length hs - lv) /\ hs_wf_elts lv hs i j} -> GTot (nhs:hashess #hsz { S.length nhs = S.length hs /\ S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\ hs_wf_elts #hsz lv nhs i s}) (decreases (S.length hs - lv)) let rec mt_retract_to_ #hsz hs lv i s j = if lv >= S.length hs then hs else begin let hvec = S.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in assert (S.length hvec = old_len); assert (new_len <= old_len); assert (new_len <= S.length hvec); let retracted = S.slice hvec 0 new_len in let nhs = S.upd hs lv retracted in if lv >= S.length hs - 1 then nhs else begin hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2); mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2) end end #pop-options val mt_retract_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> r:nat{MT?.i mt <= r /\ r < MT?.j mt} -> GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1}) let mt_retract_to #hsz mt r = let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r+1) (MT?.j mt) in MT (MT?.i mt) (r+1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) /// Verification val mt_verify_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k <= j} -> p:path #hsz -> ppos:nat -> acc:hash #hsz -> actd:bool{ppos + mt_path_length k j actd <= S.length p} -> GTot (hash #hsz) let rec mt_verify_ #hsz #f k j p ppos acc actd = if j = 0 then acc else (let nactd = actd || (j % 2 = 1) in if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then mt_verify_ #_ #f (k / 2) (j / 2) p ppos acc nactd else (let nacc = f acc (S.index p ppos) in mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd)) else (let nacc = f (S.index p ppos) acc in mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd)) val mt_verify: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k < j} -> p:path #hsz {S.length p = 1 + mt_path_length k j false} -> rt:hash #hsz ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Prims.nat -> j: Prims.nat{k < j} -> p: MerkleTree.New.High.path {FStar.Seq.Base.length p = 1 + MerkleTree.New.High.mt_path_length k j false} -> rt: MerkleTree.New.High.hash -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "MerkleTree.New.High.path", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.op_Addition", "MerkleTree.New.High.mt_path_length", "Prims.eq2", "MerkleTree.New.High.mt_verify_", "FStar.Seq.Base.index", "Prims.prop" ]
[]
false
false
false
false
true
let mt_verify #_ #f k j p rt =
let crt = mt_verify_ #_ #f k j p 1 (S.index p 0) false in crt == rt
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_get_path
val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz)
val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz)
let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 6, "end_line": 536, "start_col": 0, "start_line": 529 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) *
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mt: MerkleTree.New.High.merkle_tree{MerkleTree.New.High.mt_wf_elts mt} -> idx: Prims.nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt: MerkleTree.New.High.hash -> Prims.GTot ((Prims.nat * np: MerkleTree.New.High.path {FStar.Seq.Base.length np = 1 + MerkleTree.New.High.mt_path_length idx (MT?.j mt) false}) * MerkleTree.New.High.hash)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.New.High.merkle_tree", "MerkleTree.New.High.mt_wf_elts", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.__proj__MT__item__i", "Prims.op_LessThan", "MerkleTree.New.High.__proj__MT__item__j", "MerkleTree.New.High.hash", "FStar.Pervasives.Native.Mktuple3", "MerkleTree.New.High.path", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.op_Addition", "MerkleTree.New.High.mt_path_length", "MerkleTree.New.High.mt_get_path_", "MerkleTree.New.High.__proj__MT__item__hs", "MerkleTree.New.High.__proj__MT__item__rhs", "MerkleTree.New.High.path_insert", "FStar.Seq.Base.empty", "FStar.Seq.Base.index", "MerkleTree.New.High.hashes", "Prims.op_Subtraction", "MerkleTree.New.High.offset_of", "FStar.Pervasives.Native.tuple3", "FStar.Pervasives.Native.tuple2", "MerkleTree.New.High.mt_get_root" ]
[]
false
false
false
false
false
let mt_get_path #hsz mt idx drt =
let umt, root = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_flush_to_
val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i)
val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i)
let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 58, "end_line": 563, "start_col": 0, "start_line": 554 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j})
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> pi: Prims.nat -> i: Prims.nat{i >= pi} -> j: Prims.nat{j >= i /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs pi j} -> Prims.GTot (fhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs = 32 /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice hs 0 lv) (FStar.Seq.Base.slice fhs 0 lv) /\ MerkleTree.New.High.hs_wf_elts lv fhs i j })
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.op_GreaterThanOrEqual", "Prims.l_and", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.bool", "MerkleTree.New.High.mt_flush_to_", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.hs_wf_elts_equal", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "MerkleTree.New.High.hash", "FStar.Seq.Base.slice", "FStar.Seq.Base.index", "FStar.Seq.Base.equal", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
false
false
false
let rec mt_flush_to_ #hsz lv hs pi i j =
let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2))
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_get_path_slice
val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv))
val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv))
let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 41, "end_line": 519, "start_col": 0, "start_line": 518 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> k: Prims.nat{i <= k && k <= j} -> p: MerkleTree.New.High.path -> actd: Prims.bool -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k p actd) (FStar.Seq.Base.length p) (FStar.Seq.Base.length p + MerkleTree.New.High.mt_path_length k j actd)) (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k FStar.Seq.Base.empty actd)) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_AmpAmp", "MerkleTree.New.High.path", "Prims.bool", "MerkleTree.New.High.mt_get_path_pull", "Prims.unit" ]
[]
true
false
true
false
false
let mt_get_path_slice #hsz lv hs rhs i j k p actd =
mt_get_path_pull lv hs rhs i j k p actd
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_verify_
val mt_verify_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k <= j} -> p:path #hsz -> ppos:nat -> acc:hash #hsz -> actd:bool{ppos + mt_path_length k j actd <= S.length p} -> GTot (hash #hsz)
val mt_verify_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k <= j} -> p:path #hsz -> ppos:nat -> acc:hash #hsz -> actd:bool{ppos + mt_path_length k j actd <= S.length p} -> GTot (hash #hsz)
let rec mt_verify_ #hsz #f k j p ppos acc actd = if j = 0 then acc else (let nactd = actd || (j % 2 = 1) in if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then mt_verify_ #_ #f (k / 2) (j / 2) p ppos acc nactd else (let nacc = f acc (S.index p ppos) in mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd)) else (let nacc = f (S.index p ppos) acc in mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 63, "end_line": 668, "start_col": 0, "start_line": 659 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i) let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) val mt_flush_to_rec: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs pi j} -> Lemma (requires offset_of i <> offset_of pi) (ensures mt_flush_to_ lv hs pi i j == (let ofs = offset_of i - offset_of pi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2))) let mt_flush_to_rec #hsz lv hs pi i j = () val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush_to #hsz mt idx = let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush #hsz mt = mt_flush_to mt (MT?.j mt - 1) #push-options "--max_fuel 2" /// Retraction val mt_retract_to_: #hsz:pos -> hs:hashess #hsz {S.length hs = 32} -> lv:nat{lv < S.length hs} -> i:nat -> s:nat -> // s is the first index excluded from nhs j:nat{ i <= s /\ s <= j /\ j < pow2 (S.length hs - lv) /\ hs_wf_elts lv hs i j} -> GTot (nhs:hashess #hsz { S.length nhs = S.length hs /\ S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\ hs_wf_elts #hsz lv nhs i s}) (decreases (S.length hs - lv)) let rec mt_retract_to_ #hsz hs lv i s j = if lv >= S.length hs then hs else begin let hvec = S.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in assert (S.length hvec = old_len); assert (new_len <= old_len); assert (new_len <= S.length hvec); let retracted = S.slice hvec 0 new_len in let nhs = S.upd hs lv retracted in if lv >= S.length hs - 1 then nhs else begin hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2); mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2) end end #pop-options val mt_retract_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> r:nat{MT?.i mt <= r /\ r < MT?.j mt} -> GTot (rmt:merkle_tree #hsz {mt_wf_elts rmt /\ MT?.i rmt = MT?.i mt /\ MT?.j rmt = r + 1}) let mt_retract_to #hsz mt r = let nhs = mt_retract_to_ (MT?.hs mt) 0 (MT?.i mt) (r+1) (MT?.j mt) in MT (MT?.i mt) (r+1) nhs false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) /// Verification val mt_verify_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> k:nat -> j:nat{k <= j} -> p:path #hsz -> ppos:nat -> acc:hash #hsz -> actd:bool{ppos + mt_path_length k j actd <= S.length p} ->
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Prims.nat -> j: Prims.nat{k <= j} -> p: MerkleTree.New.High.path -> ppos: Prims.nat -> acc: MerkleTree.New.High.hash -> actd: Prims.bool{ppos + MerkleTree.New.High.mt_path_length k j actd <= FStar.Seq.Base.length p} -> Prims.GTot MerkleTree.New.High.hash
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.path", "MerkleTree.New.High.hash", "Prims.bool", "Prims.op_Addition", "MerkleTree.New.High.mt_path_length", "FStar.Seq.Base.length", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.op_BarBar", "Prims.op_AmpAmp", "Prims.op_Negation", "MerkleTree.New.High.mt_verify_", "Prims.op_Division", "MerkleTree.Spec.hash", "FStar.Seq.Base.index" ]
[ "recursion" ]
false
false
false
false
false
let rec mt_verify_ #hsz #f k j p ppos acc actd =
if j = 0 then acc else (let nactd = actd || (j % 2 = 1) in if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then mt_verify_ #_ #f (k / 2) (j / 2) p ppos acc nactd else (let nacc = f acc (S.index p ppos) in mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd)) else (let nacc = f (S.index p ppos) acc in mt_verify_ #_ #f (k / 2) (j / 2) p (ppos + 1) nacc nactd))
false
MerkleTree.New.High.fst
MerkleTree.New.High.insert_
val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j)
val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j)
let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 10, "end_line": 201, "start_col": 0, "start_line": 185 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)})
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv < 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) - 1} -> hs: MerkleTree.New.High.hashess {FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> acc: MerkleTree.New.High.hash -> Prims.GTot (ihs: MerkleTree.New.High.hashess { FStar.Seq.Base.length ihs = 32 /\ MerkleTree.New.High.hs_wf_elts lv ihs i (j + 1) /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice hs 0 lv) (FStar.Seq.Base.slice ihs 0 lv) })
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hs_wf_elts", "MerkleTree.New.High.hash", "Prims.op_Modulus", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.op_Addition", "FStar.Seq.Base.index", "MerkleTree.New.High.offset_of", "Prims.eq2", "Prims.op_Division", "MerkleTree.New.High.insert_", "MerkleTree.Spec.hash", "FStar.Seq.Properties.last", "MerkleTree.New.High.remainder_2_1_div", "Prims.bool", "MerkleTree.New.High.hashess_insert" ]
[ "recursion" ]
false
false
false
false
false
let rec insert_ #hsz #f lv i j hs acc =
let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 then (remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs) else ihs
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_retract_to_
val mt_retract_to_: #hsz:pos -> hs:hashess #hsz {S.length hs = 32} -> lv:nat{lv < S.length hs} -> i:nat -> s:nat -> // s is the first index excluded from nhs j:nat{ i <= s /\ s <= j /\ j < pow2 (S.length hs - lv) /\ hs_wf_elts lv hs i j} -> GTot (nhs:hashess #hsz { S.length nhs = S.length hs /\ S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\ hs_wf_elts #hsz lv nhs i s}) (decreases (S.length hs - lv))
val mt_retract_to_: #hsz:pos -> hs:hashess #hsz {S.length hs = 32} -> lv:nat{lv < S.length hs} -> i:nat -> s:nat -> // s is the first index excluded from nhs j:nat{ i <= s /\ s <= j /\ j < pow2 (S.length hs - lv) /\ hs_wf_elts lv hs i j} -> GTot (nhs:hashess #hsz { S.length nhs = S.length hs /\ S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\ hs_wf_elts #hsz lv nhs i s}) (decreases (S.length hs - lv))
let rec mt_retract_to_ #hsz hs lv i s j = if lv >= S.length hs then hs else begin let hvec = S.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in assert (S.length hvec = old_len); assert (new_len <= old_len); assert (new_len <= S.length hvec); let retracted = S.slice hvec 0 new_len in let nhs = S.upd hs lv retracted in if lv >= S.length hs - 1 then nhs else begin hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2); mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2) end end
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 634, "start_col": 0, "start_line": 618 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv)) let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd) #pop-options val mt_get_path_slice: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice (mt_get_path_ lv hs rhs i j k p actd) (S.length p) (S.length p + mt_path_length k j actd)) (mt_get_path_ lv hs rhs i j k S.empty actd)) (decreases (32 - lv)) let mt_get_path_slice #hsz lv hs rhs i j k p actd = mt_get_path_pull lv hs rhs i j k p actd val mt_get_path: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{MT?.i mt <= idx /\ idx < MT?.j mt} -> drt:hash #hsz -> GTot (nat * (np:path #hsz {S.length np = 1 + mt_path_length idx (MT?.j mt) false}) * hash #hsz) let mt_get_path #hsz mt idx drt = let (umt, root) = mt_get_root mt drt in let ofs = offset_of (MT?.i umt) in let np = path_insert S.empty (S.index (S.index (MT?.hs umt) 0) (idx - ofs)) in MT?.j umt, mt_get_path_ 0 (MT?.hs umt) (MT?.rhs umt) (MT?.i umt) (MT?.j umt) idx np false, root /// Flushing val mt_flush_to_: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs pi j} -> GTot (fhs:hashess{ S.length fhs = 32 /\ S.equal (S.slice hs 0 lv) (S.slice fhs 0 lv) /\ hs_wf_elts #hsz lv fhs i j}) (decreases i) let rec mt_flush_to_ #hsz lv hs pi i j = let oi = offset_of i in let opi = offset_of pi in if oi = opi then hs else (let ofs = oi - opi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ (lv + 1) nhs (pi / 2) (i / 2) (j / 2)) val mt_flush_to_rec: #hsz:pos -> lv:nat{lv < 32} -> hs:hashess #hsz {S.length hs = 32} -> pi:nat -> i:nat{i >= pi} -> j:nat{ j >= i /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs pi j} -> Lemma (requires offset_of i <> offset_of pi) (ensures mt_flush_to_ lv hs pi i j == (let ofs = offset_of i - offset_of pi in let hvec = S.index hs lv in let flushed = S.slice hvec ofs (S.length hvec) in let nhs = S.upd hs lv flushed in hs_wf_elts_equal (lv + 1) hs nhs (pi / 2) (j / 2); mt_flush_to_ #hsz (lv + 1) nhs (pi / 2) (i / 2) (j / 2))) let mt_flush_to_rec #hsz lv hs pi i j = () val mt_flush_to: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> idx:nat{idx >= MT?.i mt /\ idx < MT?.j mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush_to #hsz mt idx = let fhs = mt_flush_to_ #hsz 0 (MT?.hs mt) (MT?.i mt) idx (MT?.j mt) in MT idx (MT?.j mt) fhs (MT?.rhs_ok mt) (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_flush: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ MT?.j mt > MT?.i mt} -> GTot (fmt:merkle_tree{mt_wf_elts #hsz fmt}) let mt_flush #hsz mt = mt_flush_to mt (MT?.j mt - 1) #push-options "--max_fuel 2" /// Retraction val mt_retract_to_: #hsz:pos -> hs:hashess #hsz {S.length hs = 32} -> lv:nat{lv < S.length hs} -> i:nat -> s:nat -> // s is the first index excluded from nhs j:nat{ i <= s /\ s <= j /\ j < pow2 (S.length hs - lv) /\ hs_wf_elts lv hs i j} -> GTot (nhs:hashess #hsz { S.length nhs = S.length hs /\ S.equal (S.slice hs 0 lv) (S.slice nhs 0 lv) /\ hs_wf_elts #hsz lv nhs i s})
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> lv: Prims.nat{lv < FStar.Seq.Base.length hs} -> i: Prims.nat -> s: Prims.nat -> j: Prims.nat { i <= s /\ s <= j /\ j < Prims.pow2 (FStar.Seq.Base.length hs - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j } -> Prims.GTot (nhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length nhs = FStar.Seq.Base.length hs /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice hs 0 lv) (FStar.Seq.Base.slice nhs 0 lv) /\ MerkleTree.New.High.hs_wf_elts lv nhs i s })
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.pos", "MerkleTree.New.High.hashess", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "Prims.nat", "Prims.op_LessThan", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_GreaterThanOrEqual", "Prims.bool", "MerkleTree.New.High.mt_retract_to_", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.hs_wf_elts_equal", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "MerkleTree.New.High.hash", "Prims._assert", "MerkleTree.New.High.offset_of", "FStar.Seq.Base.index" ]
[ "recursion" ]
false
false
false
false
false
let rec mt_retract_to_ #hsz hs lv i s j =
if lv >= S.length hs then hs else let hvec = S.index hs lv in let old_len = j - offset_of i in let new_len = s - offset_of i in assert (S.length hvec = old_len); assert (new_len <= old_len); assert (new_len <= S.length hvec); let retracted = S.slice hvec 0 new_len in let nhs = S.upd hs lv retracted in if lv >= S.length hs - 1 then nhs else (hs_wf_elts_equal (lv + 1) hs nhs (i / 2) (j / 2); mt_retract_to_ nhs (lv + 1) (i / 2) (s / 2) (j / 2))
false
MerkleTree.New.High.fst
MerkleTree.New.High.construct_rhs_unchanged
val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j)
val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j)
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 63, "end_line": 310, "start_col": 0, "start_line": 296 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Seq.Base.slice rhs 0 lv) (FStar.Seq.Base.slice (FStar.Pervasives.Native.fst (MerkleTree.New.High.construct_rhs lv hs rhs i j acc actd)) 0 lv)) (decreases j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.bool", "Prims.op_Modulus", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Pervasives.Native.fst", "MerkleTree.New.High.construct_rhs", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.construct_rhs_unchanged", "FStar.Seq.Base.index", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
true
false
false
let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd =
let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv)))
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_get_path_pull
val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv))
val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd))) (decreases (32 - lv))
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 61, "end_line": 497, "start_col": 0, "start_line": 489 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv)) let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) #push-options "--z3rlimit 20" val mt_get_path_pull: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (mt_get_path_ lv hs rhs i j k p actd) (S.append p (mt_get_path_ lv hs rhs i j k S.empty actd)))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> k: Prims.nat{i <= k && k <= j} -> p: MerkleTree.New.High.path -> actd: Prims.bool -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k p actd) (FStar.Seq.Base.append p (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k FStar.Seq.Base.empty actd))) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_AmpAmp", "MerkleTree.New.High.path", "Prims.bool", "MerkleTree.New.High.mt_get_path_pull", "Prims.op_Addition", "Prims.op_Division", "MerkleTree.New.High.mt_make_path_step", "FStar.Seq.Base.empty", "Prims.unit", "Prims.precedes", "Prims.op_Modulus", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_get_path_pull #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in let nactd = if j % 2 = 0 then actd else true in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np nactd; mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) (mt_make_path_step lv hs rhs i j k S.empty actd) nactd)
false
MerkleTree.New.High.fst
MerkleTree.New.High.mt_get_path_unchanged
val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv))
val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p))) (decreases (32 - lv))
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true))
{ "file_name": "src/MerkleTree.New.High.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 41, "end_line": 469, "start_col": 0, "start_line": 462 }
module MerkleTree.New.High open FStar.Ghost open FStar.Seq module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 module MTS = MerkleTree.Spec #set-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0" type uint32_t = U32.t type uint8_t = U8.t type hash (#hsz:pos) = b:Spec.Hash.Definitions.bytes{Seq.length b = hsz} type hashes (#hsz:pos) = S.seq (hash #hsz) type hashess (#hsz:pos) = S.seq (hashes #hsz) noextract let hash_init (#hsz:pos): hash #hsz = Seq.create hsz (Lib.IntTypes.u8 0) val sha256_compress: src1:hash #32 -> src2:hash #32 -> GTot (hash #32) let sha256_compress = MTS.sha256_compress /// Facts about sequences val seq_slice_equal_index: #a:Type -> s1:S.seq a -> s2:S.seq a -> i:nat -> j:nat{i <= j && j <= S.length s1 && j <= S.length s2} -> k:nat{i <= k && k < j} -> Lemma (requires S.equal (S.slice s1 i j) (S.slice s2 i j)) (ensures S.index s1 k == S.index s2 k) [SMTPat (S.equal (S.slice s1 i j) (S.slice s2 i j)); SMTPat (S.index s1 k)] let seq_slice_equal_index #a s1 s2 i j k = assert (S.index (S.slice s1 i j) (k - i) == S.index (S.slice s2 i j) (k - i)) private val seq_slice_more_equal: #a:Type -> s1:S.seq a -> s2:S.seq a -> n:nat -> m:nat{n <= m && m <= S.length s1 && m <= S.length s2} -> k:nat{n <= k} -> l:nat{k <= l && l <= m} -> Lemma (requires S.equal (S.slice s1 n m) (S.slice s2 n m)) (ensures S.equal (S.slice s1 k l) (S.slice s2 k l)) [SMTPat (S.equal (S.slice s1 n m) (S.slice s2 n m)); SMTPat (S.equal (S.slice s1 k l) (S.slice s2 k l))] private let seq_slice_more_equal #a s1 s2 n m k l = slice_slice s1 n m (k - n) (l - n); slice_slice s2 n m (k - n) (l - n) /// Facts about "2" val remainder_2_not_1_div: n:nat -> Lemma (requires n % 2 <> 1) (ensures n / 2 = (n + 1) / 2) let remainder_2_not_1_div n = () val remainder_2_1_div: n:nat -> Lemma (requires n % 2 = 1) (ensures n / 2 + 1 = (n + 1) / 2) let remainder_2_1_div n = () /// High-level Merkle tree data structure noeq type merkle_tree (#hsz:pos) = | MT: i:nat -> j:nat{i <= j && j < pow2 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs_ok:bool -> rhs:hashes #hsz {S.length rhs = 32} -> // Rightmost hashes mroot:hash #hsz -> hash_fun:MTS.hash_fun_t #hsz -> merkle_tree #hsz val mt_not_full (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_full #hsz mt = MT?.j mt < pow2 32 - 1 val mt_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_empty #hsz mt = MT?.j mt = 0 val mt_not_empty (#hsz:pos): merkle_tree #hsz -> GTot bool let mt_not_empty #hsz mt = MT?.j mt > 0 /// Well-formedness w.r.t. indices of base hash elements noextract val offset_of: i:nat -> Tot nat let offset_of i = if i % 2 = 0 then i else i - 1 val hs_wf_elts: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> i:nat -> j:nat{j >= i} -> GTot Type0 (decreases (32 - lv)) let rec hs_wf_elts #hsz lv hs i j = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index hs lv) == j - ofs /\ hs_wf_elts #hsz (lv + 1) hs (i / 2) (j / 2)) #push-options "--max_fuel 1" val hs_wf_elts_equal: #hsz:pos -> lv:nat{lv <= 32} -> hs1:hashess #hsz {S.length hs1 = 32} -> hs2:hashess #hsz {S.length hs2 = 32} -> i:nat -> j:nat{j >= i} -> Lemma (requires hs_wf_elts lv hs1 i j /\ S.equal (S.slice hs1 lv 32) (S.slice hs2 lv 32)) (ensures hs_wf_elts lv hs2 i j) (decreases (32 - lv)) let rec hs_wf_elts_equal #hsz lv hs1 hs2 i j = if lv = 32 then () else (S.slice_slice hs1 lv 32 1 (32 - lv); S.slice_slice hs2 lv 32 1 (32 - lv); assert (S.equal (S.slice hs1 (lv + 1) 32) (S.slice hs2 (lv + 1) 32)); S.lemma_index_slice hs1 lv 32 0; S.lemma_index_slice hs2 lv 32 0; assert (S.index hs1 lv == S.index hs2 lv); hs_wf_elts_equal (lv + 1) hs1 hs2 (i / 2) (j / 2)) val mt_wf_elts (#hsz:pos): merkle_tree #hsz -> GTot Type0 let mt_wf_elts #_ (MT i j hs _ _ _ _) = hs_wf_elts 0 hs i j /// Construction val hs_wf_elts_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures hs_wf_elts #hsz lv (S.create 32 S.empty) 0 0) (decreases (32 - lv)) let rec hs_wf_elts_empty #hsz lv = if lv = 32 then () else hs_wf_elts_empty #hsz (lv + 1) // NOTE: the public function is `create_mt` defined below, which // builds a tree with an initial hash. noextract inline_for_extraction val create_empty_mt (#hsz:pos) (#f:MTS.hash_fun_t #hsz): unit -> GTot (mt:merkle_tree #hsz {mt_wf_elts #hsz mt}) let create_empty_mt #hsz #f _ = hs_wf_elts_empty #hsz 0; MT 0 0 (S.create 32 S.empty) false (S.create 32 (hash_init #hsz)) (hash_init #hsz) f /// Insertion val hashess_insert: #hsz:pos -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> v:hash #hsz -> GTot (ihs:hashess #hsz {S.length ihs = 32 /\ hs_wf_elts (lv + 1) ihs (i / 2) (j / 2)}) let hashess_insert #hsz lv i j hs v = let ihs = S.upd hs lv (S.snoc (S.index hs lv) v) in hs_wf_elts_equal (lv + 1) hs ihs (i / 2) (j / 2); ihs val insert_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv) - 1} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> acc:hash #hsz -> GTot (ihs:hashess #hsz { S.length ihs = 32 /\ hs_wf_elts #hsz lv ihs i (j + 1) /\ S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)}) (decreases j) let rec insert_ #hsz #f lv i j hs acc = let ihs = hashess_insert #hsz lv i j hs acc in assert (S.equal (S.slice hs 0 lv) (S.slice ihs 0 lv)); if j % 2 = 1 // S.length (S.index hs lv) > 0 then begin remainder_2_1_div j; let nacc = f (S.last (S.index hs lv)) acc in let rihs = insert_ #hsz #f (lv + 1) (i / 2) (j / 2) ihs nacc in assert (hs_wf_elts #hsz (lv + 1) rihs (i / 2) (j / 2 + 1)); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.index ihs lv == S.index rihs lv); assert (S.length (S.index rihs lv) = (j + 1) - offset_of i); assert (S.equal (S.slice ihs 0 (lv + 1)) (S.slice rihs 0 (lv + 1))); assert (S.equal (S.slice ihs 0 lv) (S.slice rihs 0 lv)); rihs end else ihs val insert_base: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess #hsz -> acc:hash #hsz -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 <> 1) (ensures S.equal (insert_ #_ #f lv i j hs acc) (hashess_insert lv i j hs acc)) let insert_base #_ #_ lv i j hs acc = () val insert_rec: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat -> i:nat -> j:nat -> hs:hashess -> acc:hash -> Lemma (requires lv < 32 /\ i <= j /\ j < pow2 (32 - lv) - 1 /\ S.length hs = 32 /\ hs_wf_elts lv hs i j /\ j % 2 == 1) (ensures (hs_wf_elts_equal (lv + 1) hs (hashess_insert lv i j hs acc) (i / 2) (j / 2); S.equal (insert_ #_ #f lv i j hs acc) (insert_ #_ #f (lv + 1) (i / 2) (j / 2) (hashess_insert lv i j hs acc) (f (S.last (S.index hs lv)) acc)))) let insert_rec #_ #_ lv i j hs acc = () val mt_insert: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt /\ mt_not_full mt} -> v:hash #hsz -> GTot (imt:merkle_tree #hsz{mt_wf_elts #hsz imt}) let mt_insert #hsz mt v = MT (MT?.i mt) (MT?.j mt + 1) (insert_ #_ #(MT?.hash_fun mt) 0 (MT?.i mt) (MT?.j mt) (MT?.hs mt) v) false (MT?.rhs mt) (MT?.mroot mt) (MT?.hash_fun mt) val mt_create: hsz:pos -> f:MTS.hash_fun_t #hsz -> init:hash #hsz -> GTot (mt:merkle_tree{mt_wf_elts #hsz mt}) let mt_create hsz f init = mt_insert #_ (create_empty_mt #_ #f ()) init /// Getting the Merkle root and path type path (#hsz:pos) = S.seq (hash #hsz) // Construct the rightmost hashes for a given (incomplete) Merkle tree. // This function calculates the Merkle root as well, which is the final // accumulator value. val construct_rhs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> GTot (crhs:hashes #hsz {S.length crhs = 32} * (hash #hsz)) (decreases j) let rec construct_rhs #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then (rhs, acc) else (if j % 2 = 0 then (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) val construct_rhs_unchanged: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal (S.slice rhs 0 lv) (S.slice (fst (construct_rhs #_ #f lv hs rhs i j acc actd)) 0 lv)) (decreases j) let rec construct_rhs_unchanged #hsz #f lv hs rhs i j acc actd = let ofs = offset_of i in if j = 0 then () else if j % 2 = 0 then (construct_rhs_unchanged #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) in assert (S.equal (S.slice rhs 0 lv) (S.slice rrhs 0 lv))) else (let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true; let rrhs = fst (construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true) in assert (S.equal (S.slice nrhs 0 lv) (S.slice rrhs 0 lv)); assert (S.equal (S.slice rhs 0 lv) (S.slice nrhs 0 lv))) val construct_rhs_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> acc:hash #hsz -> actd:bool -> Lemma (requires j <> 0 /\ j % 2 = 0) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == construct_rhs #_ #f (lv + 1) hs rhs (i / 2) (j / 2) acc actd) let construct_rhs_even #_ #_ _ _ _ _ _ _ _ = () val construct_rhs_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> acc:hash -> actd:bool -> Lemma (requires j % 2 = 1) (ensures construct_rhs #_ #f lv hs rhs i j acc actd == (let ofs = offset_of i in let nrhs = if actd then S.upd rhs lv acc else rhs in let nacc = if actd then f (S.index (S.index hs lv) (j - 1 - ofs)) acc else S.index (S.index hs lv) (j - 1 - ofs) in construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true)) let construct_rhs_odd #_ #_ _ _ _ _ _ _ _ = () val mt_get_root: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts #hsz mt} -> drt:hash #hsz -> GTot (merkle_tree #hsz * hash #hsz) let mt_get_root #hsz mt drt = if MT?.rhs_ok mt then (mt, MT?.mroot mt) else begin let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt) end val mt_get_root_rhs_ok_true: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash #hsz -> Lemma (requires MT?.rhs_ok mt == true) (ensures mt_get_root #hsz mt drt == (mt, MT?.mroot mt)) let mt_get_root_rhs_ok_true #hsz mt drt = () val mt_get_root_rhs_ok_false: #hsz:pos -> mt:merkle_tree #hsz {mt_wf_elts mt} -> drt:hash -> Lemma (requires MT?.rhs_ok mt == false) (ensures mt_get_root mt drt == (let (nrhs, rt) = construct_rhs #_ #(MT?.hash_fun mt) 0 (MT?.hs mt) (MT?.rhs mt) (MT?.i mt) (MT?.j mt) drt false in (MT (MT?.i mt) (MT?.j mt) (MT?.hs mt) true nrhs rt (MT?.hash_fun mt), rt))) let mt_get_root_rhs_ok_false #_ _ _ = () val path_insert: (#hsz:pos) -> p:path #hsz -> hp:hash #hsz -> GTot (path #hsz) let path_insert #_ p hp = S.snoc p hp val mt_path_length_step: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let mt_path_length_step k j actd = if j = 0 then 0 else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then 0 else 1) else 1) val mt_path_length: k:nat -> j:nat{k <= j} -> actd:bool -> GTot nat let rec mt_path_length k j actd = if j = 0 then 0 else (let nactd = actd || (j % 2 = 1) in mt_path_length_step k j actd + mt_path_length (k / 2) (j / 2) nactd) val mt_make_path_step: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ j <> 0 /\ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (path #hsz) let mt_make_path_step #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if k % 2 = 1 then path_insert p (S.index (S.index hs lv) (k - 1 - ofs)) else (if k = j then p else if k + 1 = j then (if actd then path_insert p (S.index rhs lv) else p) else path_insert p (S.index (S.index hs lv) (k + 1 - ofs))) // Construct a Merkle path for a given index `k`, hashes `hs`, // and rightmost hashes `rhs`. val mt_get_path_: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> GTot (np:path #hsz {S.length np = S.length p + mt_path_length k j actd}) (decreases (32 - lv)) let rec mt_get_path_ #hsz lv hs rhs i j k p actd = let ofs = offset_of i in if j = 0 then p else (let np = mt_make_path_step lv hs rhs i j k p actd in mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true)) val mt_get_path_unchanged: #hsz:pos -> lv:nat{lv <= 32} -> hs:hashess #hsz {S.length hs = 32} -> rhs:hashes #hsz {S.length rhs = 32} -> i:nat -> j:nat{ i <= j /\ j < pow2 (32 - lv) /\ hs_wf_elts #hsz lv hs i j} -> k:nat{i <= k && k <= j} -> p:path #hsz -> actd:bool -> Lemma (requires True) (ensures S.equal p (S.slice (mt_get_path_ lv hs rhs i j k p actd) 0 (S.length p)))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "MerkleTree.Spec.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> hs: MerkleTree.New.High.hashess{FStar.Seq.Base.length hs = 32} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> k: Prims.nat{i <= k && k <= j} -> p: MerkleTree.New.High.path -> actd: Prims.bool -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal p (FStar.Seq.Base.slice (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k p actd) 0 (FStar.Seq.Base.length p))) (decreases 32 - lv)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.hash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hs_wf_elts", "Prims.op_AmpAmp", "MerkleTree.New.High.path", "Prims.bool", "MerkleTree.New.High.mt_get_path_unchanged", "Prims.op_Addition", "Prims.op_Division", "Prims.op_Modulus", "Prims.precedes", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "MerkleTree.New.High.mt_make_path_step", "MerkleTree.New.High.offset_of" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_get_path_unchanged #hsz lv hs rhs i j k p actd =
let ofs = offset_of i in if j = 0 then () else (let np = mt_make_path_step lv hs rhs i j k p actd in assert (S.equal p (S.slice np 0 (S.length p))); mt_get_path_unchanged (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) np (if j % 2 = 0 then actd else true))
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.mul_qmont_R_and_R_inv_is_one
val mul_qmont_R_and_R_inv_is_one: unit -> Lemma (qmont_R * qmont_R_inv % S.order = 1)
val mul_qmont_R_and_R_inv_is_one: unit -> Lemma (qmont_R * qmont_R_inv % S.order = 1)
let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1)
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 244, "start_col": 0, "start_line": 239 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.Montgomery.qmont_R * Hacl.Spec.P256.Montgomery.qmont_R_inv % Spec.P256.PointOps.order = 1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "Prims.int", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "Prims.op_Modulus", "FStar.Mul.op_Star", "Spec.P256.PointOps.order", "Prims.pow2", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Hacl.Spec.Montgomery.Lemmas.mont_preconditions_d", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd" ]
[]
false
false
true
false
false
let mul_qmont_R_and_R_inv_is_one () =
let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert ((d % S.order) * pow2 256 % S.order = 1)
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add_mod_n_u64
val bn_add_mod_n_u64 (len: size_t{v len > 0}) : bn_add_mod_n_st U64 len
val bn_add_mod_n_u64 (len: size_t{v len > 0}) : bn_add_mod_n_st U64 len
let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 98, "start_col": 0, "start_line": 98 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_add_mod_n_st Lib.IntTypes.U64 len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.bn_add_mod_n", "Lib.IntTypes.U64", "Hacl.Bignum.bn_add_mod_n_st" ]
[]
false
false
false
false
false
let bn_add_mod_n_u64 (len: size_t{v len > 0}) : bn_add_mod_n_st U64 len =
bn_add_mod_n len
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add_mod_n_u32
val bn_add_mod_n_u32 (len: size_t{v len > 0}) : bn_add_mod_n_st U32 len
val bn_add_mod_n_u32 (len: size_t{v len > 0}) : bn_add_mod_n_st U32 len
let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 97, "start_col": 0, "start_line": 97 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_add_mod_n_st Lib.IntTypes.U32 len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.bn_add_mod_n", "Hacl.Bignum.bn_add_mod_n_st" ]
[]
false
false
false
false
false
let bn_add_mod_n_u32 (len: size_t{v len > 0}) : bn_add_mod_n_st U32 len =
bn_add_mod_n len
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub
val bn_sub: #t:limb_t -> bn_sub_st t
val bn_sub: #t:limb_t -> bn_sub_st t
let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 23, "start_col": 0, "start_line": 22 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Bignum.bn_sub_st t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Addition.bn_sub", "Hacl.Spec.Bignum.Base.carry" ]
[]
false
false
false
false
false
let bn_sub #t aLen a bLen b res =
Hacl.Bignum.Addition.bn_sub aLen a bLen b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub_mod_n_u64
val bn_sub_mod_n_u64 (len: size_t{v len > 0}) : bn_sub_mod_n_st U64 len
val bn_sub_mod_n_u64 (len: size_t{v len > 0}) : bn_sub_mod_n_st U64 len
let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 107, "start_col": 0, "start_line": 107 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_sub_mod_n_st Lib.IntTypes.U64 len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.bn_sub_mod_n", "Lib.IntTypes.U64", "Hacl.Bignum.bn_sub_mod_n_st" ]
[]
false
false
false
false
false
let bn_sub_mod_n_u64 (len: size_t{v len > 0}) : bn_sub_mod_n_st U64 len =
bn_sub_mod_n len
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub_mod_n_u32
val bn_sub_mod_n_u32 (len: size_t{v len > 0}) : bn_sub_mod_n_st U32 len
val bn_sub_mod_n_u32 (len: size_t{v len > 0}) : bn_sub_mod_n_st U32 len
let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 106, "start_col": 0, "start_line": 106 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_sub_mod_n_st Lib.IntTypes.U32 len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.bn_sub_mod_n", "Hacl.Bignum.bn_sub_mod_n_st" ]
[]
false
false
false
false
false
let bn_sub_mod_n_u32 (len: size_t{v len > 0}) : bn_sub_mod_n_st U32 len =
bn_sub_mod_n len
false
Benton2004.SmithVolpano.fsti
Benton2004.SmithVolpano.eval_equiv
val eval_equiv (#t: Type0) (c: context) (f: exp t) (s: seclevel) : GTot Type0
val eval_equiv (#t: Type0) (c: context) (f: exp t) (s: seclevel) : GTot Type0
let eval_equiv (#t: Type0) (c: context) (f: exp t) (s: seclevel) : GTot Type0 = Benton2004.DDCC.eval_equiv (interp_context c) (interp_seclevel _ s) f f
{ "file_name": "examples/rel/Benton2004.SmithVolpano.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 43, "start_col": 0, "start_line": 37 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004.SmithVolpano include Benton2004.DDCC type seclevel = | Low | High let interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t) = match s with | Low -> ns_delta | High -> ns_t type context = (l: list (var * seclevel) { List.Tot.noRepeats (List.Tot.map fst l) } ) let rec interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x' . List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi)) = match gamma with | [] -> st_nil | (x, s) :: gamma' -> st_cons (interp_context gamma') x (interp_seclevel int s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "Benton2004.DDCC.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.SmithVolpano.fsti" }
[ { "abbrev": false, "full_module": "Benton2004.DDCC", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Benton2004.SmithVolpano.context -> f: Benton2004.exp t -> s: Benton2004.SmithVolpano.seclevel -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.SmithVolpano.context", "Benton2004.exp", "Benton2004.SmithVolpano.seclevel", "Benton2004.eval_equiv", "Benton2004.SmithVolpano.interp_context", "Benton2004.SmithVolpano.interp_seclevel" ]
[]
false
false
false
false
true
let eval_equiv (#t: Type0) (c: context) (f: exp t) (s: seclevel) : GTot Type0 =
Benton2004.DDCC.eval_equiv (interp_context c) (interp_seclevel _ s) f f
false
Benton2004.SmithVolpano.fsti
Benton2004.SmithVolpano.strong_sequential_noninterference
val strong_sequential_noninterference (gamma: context) (c: computation) : GTot Type0
val strong_sequential_noninterference (gamma: context) (c: computation) : GTot Type0
let strong_sequential_noninterference (gamma: context) (c: computation) : GTot Type0 = exec_equiv gamma c Low
{ "file_name": "examples/rel/Benton2004.SmithVolpano.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 208, "start_col": 0, "start_line": 204 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004.SmithVolpano include Benton2004.DDCC type seclevel = | Low | High let interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t) = match s with | Low -> ns_delta | High -> ns_t type context = (l: list (var * seclevel) { List.Tot.noRepeats (List.Tot.map fst l) } ) let rec interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x' . List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi)) = match gamma with | [] -> st_nil | (x, s) :: gamma' -> st_cons (interp_context gamma') x (interp_seclevel int s) let eval_equiv (#t: Type0) (c: context) (f: exp t) (s: seclevel) : GTot Type0 = Benton2004.DDCC.eval_equiv (interp_context c) (interp_seclevel _ s) f f val eval_equiv_def (#t: Type0) (gamma: context) (f: exp t) (s: seclevel) : Lemma (eval_equiv gamma f s <==> Benton2004.DDCC.eval_equiv (interp_context gamma) (interp_seclevel _ s) f f) val exec_equiv (gamma: context) (c: computation) (s: seclevel) : GTot Type0 val exec_equiv_def (gamma: context) (c: computation) (s: seclevel) : Lemma (exec_equiv gamma c s <==> Benton2004.DDCC.exec_equiv (interp_context gamma) (interp_context gamma) c (match s with Low -> c | High -> skip)) (* Figure 4 *) let fresh_in (x: var) (gamma: context) : GTot Type0 = List.Tot.mem x (List.Tot.map fst gamma) == false val eval_equiv_var_same (gamma: context) (x: var) (s: seclevel) : Lemma (requires (x `fresh_in` gamma)) (ensures ( x `fresh_in` gamma /\ eval_equiv ((x, s) :: gamma) (evar x) s )) [SMTPat (eval_equiv ((x, s)::gamma) (evar x) s)] val eval_equiv_var_other (gamma: context) (x y: var) (sx sy: seclevel) : Lemma (requires ( y `fresh_in` gamma /\ x <> y /\ eval_equiv gamma (evar x) sx )) (ensures ( y `fresh_in` gamma /\ eval_equiv ((y, sy) :: gamma) (evar x) sx )) [SMTPat (eval_equiv ((y, sy)::gamma) (evar x) sx)] val eval_equiv_const (#t: Type0) (gamma: context) (c: t) (s: seclevel) : Lemma (eval_equiv gamma (const c) s) [SMTPat (eval_equiv gamma (const c) s)] val op_abs_interp_seclevel (#from #to: Type0) (op: (from -> from -> Tot to)) (s: seclevel) : Lemma (op_abs op (interp_seclevel _ s) (interp_seclevel _ s) (interp_seclevel _ s)) val eval_equiv_op (#from #to: Type0) (op: (from -> from -> Tot to)) (gamma: context) (e e' : exp from) (s: seclevel) : Lemma (requires ( eval_equiv gamma e s /\ eval_equiv gamma e' s )) (ensures (eval_equiv gamma (eop op e e') s)) [SMTPat (eval_equiv gamma (eop op e e') s)] val exec_equiv_assign (gamma: context) (x: var) (e: exp int) (s: seclevel) : Lemma (requires ( x `fresh_in` gamma /\ eval_equiv ((x, s)::gamma) e s )) (ensures ( x `fresh_in` gamma /\ exec_equiv ((x, s)::gamma) (assign x e) s )) [SMTPat (exec_equiv ((x, s)::gamma) (assign x e) s)] val exec_equiv_seq (gamma: context) (c c' : computation) (s: seclevel) : Lemma (requires ( exec_equiv gamma c s /\ exec_equiv gamma c' s )) (ensures ( exec_equiv gamma (seq c c') s )) [SMTPat (exec_equiv gamma (seq c c') s)] val exec_equiv_ifthenelse (gamma: context) (b: exp bool) (c c' : computation) (s: seclevel) : Lemma (requires ( eval_equiv gamma b s /\ exec_equiv gamma c s /\ exec_equiv gamma c' s )) (ensures (exec_equiv gamma (ifthenelse b c c') s)) [SMTPat (exec_equiv gamma (ifthenelse b c c') s)] val exec_equiv_while (gamma: context) (b: exp bool) (c: computation) : Lemma (requires ( eval_equiv gamma b Low /\ exec_equiv gamma c Low )) (ensures (exec_equiv gamma (while b c) Low)) [SMTPat (exec_equiv gamma (while b c) Low)] val eval_equiv_low_to_high (#t: Type0) (gamma: context) (e: exp t) : Lemma (requires (eval_equiv gamma e Low)) (ensures (eval_equiv gamma e High)) [SMTPat (eval_equiv gamma e High)] val exec_equiv_high_to_low (gamma: context) (c: computation) : Lemma (requires (exec_equiv gamma c High)) (ensures (exec_equiv gamma c Low)) [SMTPat (exec_equiv gamma c Low)] (* Definition 2 *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "Benton2004.DDCC.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.SmithVolpano.fsti" }
[ { "abbrev": false, "full_module": "Benton2004.DDCC", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
gamma: Benton2004.SmithVolpano.context -> c: Benton2004.computation -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.SmithVolpano.context", "Benton2004.computation", "Benton2004.SmithVolpano.exec_equiv", "Benton2004.SmithVolpano.Low" ]
[]
false
false
false
false
true
let strong_sequential_noninterference (gamma: context) (c: computation) : GTot Type0 =
exec_equiv gamma c Low
false
Benton2004.SmithVolpano.fsti
Benton2004.SmithVolpano.fresh_in
val fresh_in (x: var) (gamma: context) : GTot Type0
val fresh_in (x: var) (gamma: context) : GTot Type0
let fresh_in (x: var) (gamma: context) : GTot Type0 = List.Tot.mem x (List.Tot.map fst gamma) == false
{ "file_name": "examples/rel/Benton2004.SmithVolpano.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 69, "start_col": 0, "start_line": 68 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004.SmithVolpano include Benton2004.DDCC type seclevel = | Low | High let interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t) = match s with | Low -> ns_delta | High -> ns_t type context = (l: list (var * seclevel) { List.Tot.noRepeats (List.Tot.map fst l) } ) let rec interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x' . List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi)) = match gamma with | [] -> st_nil | (x, s) :: gamma' -> st_cons (interp_context gamma') x (interp_seclevel int s) let eval_equiv (#t: Type0) (c: context) (f: exp t) (s: seclevel) : GTot Type0 = Benton2004.DDCC.eval_equiv (interp_context c) (interp_seclevel _ s) f f val eval_equiv_def (#t: Type0) (gamma: context) (f: exp t) (s: seclevel) : Lemma (eval_equiv gamma f s <==> Benton2004.DDCC.eval_equiv (interp_context gamma) (interp_seclevel _ s) f f) val exec_equiv (gamma: context) (c: computation) (s: seclevel) : GTot Type0 val exec_equiv_def (gamma: context) (c: computation) (s: seclevel) : Lemma (exec_equiv gamma c s <==> Benton2004.DDCC.exec_equiv (interp_context gamma) (interp_context gamma) c (match s with Low -> c | High -> skip)) (* Figure 4 *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "Benton2004.DDCC.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.SmithVolpano.fsti" }
[ { "abbrev": false, "full_module": "Benton2004.DDCC", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Benton2004.var -> gamma: Benton2004.SmithVolpano.context -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.var", "Benton2004.SmithVolpano.context", "Prims.eq2", "Prims.bool", "FStar.List.Tot.Base.mem", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.tuple2", "Benton2004.SmithVolpano.seclevel", "FStar.Pervasives.Native.fst" ]
[]
false
false
false
false
true
let fresh_in (x: var) (gamma: context) : GTot Type0 =
List.Tot.mem x (List.Tot.map fst gamma) == false
false
Benton2004.SmithVolpano.fsti
Benton2004.SmithVolpano.interp_context
val interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x'. List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi))
val interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x'. List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi))
let rec interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x' . List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi)) = match gamma with | [] -> st_nil | (x, s) :: gamma' -> st_cons (interp_context gamma') x (interp_seclevel int s)
{ "file_name": "examples/rel/Benton2004.SmithVolpano.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 81, "end_line": 35, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004.SmithVolpano include Benton2004.DDCC type seclevel = | Low | High let interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t) = match s with | Low -> ns_delta | High -> ns_t type context = (l: list (var * seclevel) { List.Tot.noRepeats (List.Tot.map fst l) } )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "Benton2004.DDCC.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.SmithVolpano.fsti" }
[ { "abbrev": false, "full_module": "Benton2004.DDCC", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
gamma: Benton2004.SmithVolpano.context -> Prims.Ghost Benton2004.DDCC.sttype
Prims.Ghost
[]
[]
[ "Benton2004.SmithVolpano.context", "Benton2004.DDCC.st_nil", "Benton2004.var", "Benton2004.SmithVolpano.seclevel", "Prims.list", "FStar.Pervasives.Native.tuple2", "Benton2004.DDCC.st_cons", "Benton2004.SmithVolpano.interp_context", "Benton2004.SmithVolpano.interp_seclevel", "Prims.int", "Benton2004.DDCC.sttype", "Prims.l_True", "Prims.l_Forall", "Prims.l_imp", "Prims.eq2", "Prims.bool", "FStar.List.Tot.Base.mem", "FStar.List.Tot.Base.map", "FStar.Pervasives.Native.fst", "Benton2004.DDCC.st_fresh_in" ]
[ "recursion" ]
false
false
false
false
false
let rec interp_context (gamma: context) : Ghost sttype (requires True) (ensures (fun phi -> forall x'. List.Tot.mem x' (List.Tot.map fst gamma) == false ==> x' `st_fresh_in` phi)) =
match gamma with | [] -> st_nil | (x, s) :: gamma' -> st_cons (interp_context gamma') x (interp_seclevel int s)
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add
val bn_add: #t:limb_t -> bn_add_st t
val bn_add: #t:limb_t -> bn_add_st t
let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 20, "start_col": 0, "start_line": 19 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Bignum.bn_add_st t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Addition.bn_add", "Hacl.Spec.Bignum.Base.carry" ]
[]
false
false
false
false
false
let bn_add #t aLen a bLen b res =
Hacl.Bignum.Addition.bn_add aLen a bLen b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add1
val bn_add1: #t:limb_t -> aLen:size_t{0 < v aLen} -> a:lbignum t aLen -> b1:limb t -> res:lbignum t aLen -> Stack (carry t) (requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (let c, r = S.bn_add1 (as_seq h0 a) b1 in c_out == c /\ as_seq h1 res == r))
val bn_add1: #t:limb_t -> aLen:size_t{0 < v aLen} -> a:lbignum t aLen -> b1:limb t -> res:lbignum t aLen -> Stack (carry t) (requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (let c, r = S.bn_add1 (as_seq h0 a) b1 in c_out == c /\ as_seq h1 res == r))
let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 8, "start_col": 0, "start_line": 7 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
aLen: Lib.IntTypes.size_t{0 < Lib.IntTypes.v aLen} -> a: Hacl.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Bignum.Definitions.limb t -> res: Hacl.Bignum.Definitions.lbignum t aLen -> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Hacl.Bignum.Addition.bn_add1", "Hacl.Spec.Bignum.Base.carry" ]
[]
false
true
false
false
false
let bn_add1 #t aLen a b1 res =
Hacl.Bignum.Addition.bn_add1 aLen a b1 res
false
Benton2004.SmithVolpano.fsti
Benton2004.SmithVolpano.interp_seclevel
val interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t)
val interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t)
let interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t) = match s with | Low -> ns_delta | High -> ns_t
{ "file_name": "examples/rel/Benton2004.SmithVolpano.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 24, "start_col": 0, "start_line": 21 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004.SmithVolpano include Benton2004.DDCC type seclevel = | Low | High
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "Benton2004.DDCC.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.SmithVolpano.fsti" }
[ { "abbrev": false, "full_module": "Benton2004.DDCC", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "Benton2004", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Type0 -> s: Benton2004.SmithVolpano.seclevel -> Prims.GTot (Benton2004.DDCC.nstype t)
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.SmithVolpano.seclevel", "Benton2004.DDCC.ns_delta", "Benton2004.DDCC.ns_t", "Benton2004.DDCC.nstype" ]
[]
false
false
false
false
false
let interp_seclevel (t: Type0) (s: seclevel) : GTot (nstype t) =
match s with | Low -> ns_delta | High -> ns_t
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add_mod_n
val bn_add_mod_n: #t:limb_t -> len:size_t{v len > 0} -> bn_add_mod_n_st t len
val bn_add_mod_n: #t:limb_t -> len:size_t{v len > 0} -> bn_add_mod_n_st t len
let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 35, "start_col": 0, "start_line": 33 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_add_mod_n_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.bn_reduce_once", "Prims.unit", "Hacl.Spec.Bignum.Base.carry", "Hacl.Bignum.bn_add_eq_len" ]
[]
false
false
false
false
false
let bn_add_mod_n #t len n a b res =
let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub_eq_len
val bn_sub_eq_len: #t:limb_t -> len:size_t -> bn_sub_eq_len_st t len
val bn_sub_eq_len: #t:limb_t -> len:size_t -> bn_sub_eq_len_st t len
let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 17, "start_col": 0, "start_line": 16 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> Hacl.Bignum.bn_sub_eq_len_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Addition.bn_sub_eq_len", "Hacl.Spec.Bignum.Base.carry" ]
[]
false
false
false
false
false
let bn_sub_eq_len #t aLen a b res =
Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add_eq_len
val bn_add_eq_len: #t:limb_t -> len:size_t -> bn_add_eq_len_st t len
val bn_add_eq_len: #t:limb_t -> len:size_t -> bn_add_eq_len_st t len
let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 14, "start_col": 0, "start_line": 13 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> Hacl.Bignum.bn_add_eq_len_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Addition.bn_add_eq_len", "Hacl.Spec.Bignum.Base.carry" ]
[]
false
false
false
false
false
let bn_add_eq_len #t aLen a b res =
Hacl.Bignum.Addition.bn_add_eq_len aLen a b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub1
val bn_sub1: #t:limb_t -> aLen:size_t{0 < v aLen} -> a:lbignum t aLen -> b1:limb t -> res:lbignum t aLen -> Stack (carry t) (requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (let c, r = S.bn_sub1 (as_seq h0 a) b1 in c_out == c /\ as_seq h1 res == r))
val bn_sub1: #t:limb_t -> aLen:size_t{0 < v aLen} -> a:lbignum t aLen -> b1:limb t -> res:lbignum t aLen -> Stack (carry t) (requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (let c, r = S.bn_sub1 (as_seq h0 a) b1 in c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 11, "start_col": 0, "start_line": 10 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
aLen: Lib.IntTypes.size_t{0 < Lib.IntTypes.v aLen} -> a: Hacl.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Bignum.Definitions.limb t -> res: Hacl.Bignum.Definitions.lbignum t aLen -> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Hacl.Bignum.Addition.bn_sub1", "Hacl.Spec.Bignum.Base.carry" ]
[]
false
true
false
false
false
let bn_sub1 #t aLen a b1 res =
Hacl.Bignum.Addition.bn_sub1 aLen a b1 res
false
StRel.fst
StRel.f1_hp
val f1_hp : heap -> ref int -> GTot (heap * int)
val f1_hp : heap -> ref int -> GTot (heap * int)
let f1_hp h x = h, sel h x
{ "file_name": "examples/rel/StRel.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 25, "start_col": 0, "start_line": 25 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module StRel open Rel open FStar.Heap open FStar.ST (* Pure relational reasoning about stateful functions *) (* Pure functions using heap passing *)
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "StRel.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.Heap.heap -> x: FStar.ST.ref Prims.int -> Prims.GTot (FStar.Monotonic.Heap.heap * Prims.int)
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.Heap.heap", "FStar.ST.ref", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "FStar.Monotonic.Heap.sel", "FStar.Heap.trivial_preorder", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let f1_hp h x =
h, sel h x
false
Hacl.Bignum.fst
Hacl.Bignum.bn_mul
val bn_mul: #t:limb_t -> aLen:size_t -> bLen:size_t{v aLen + v bLen <= max_size_t} -> a:lbignum t aLen -> bn_mul_st t aLen bLen a
val bn_mul: #t:limb_t -> aLen:size_t -> bLen:size_t{v aLen + v bLen <= max_size_t} -> a:lbignum t aLen -> bn_mul_st t aLen bLen a
let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 56, "start_col": 0, "start_line": 55 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
aLen: Lib.IntTypes.size_t -> bLen: Lib.IntTypes.size_t{Lib.IntTypes.v aLen + Lib.IntTypes.v bLen <= Lib.IntTypes.max_size_t} -> a: Hacl.Bignum.Definitions.lbignum t aLen -> Hacl.Bignum.bn_mul_st t aLen bLen a
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Hacl.Bignum.Multiplication.bn_mul", "Prims.unit" ]
[]
false
false
false
false
false
let bn_mul #t aLen bLen a b res =
Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sqr
val bn_sqr: #t:limb_t -> len:size_t{0 < v len /\ v len + v len <= max_size_t} -> a:lbignum t len -> bn_sqr_st t len a
val bn_sqr: #t:limb_t -> len:size_t{0 < v len /\ v len + v len <= max_size_t} -> a:lbignum t len -> bn_sqr_st t len a
let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 66, "start_col": 0, "start_line": 63 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.v len + Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> a: Hacl.Bignum.Definitions.lbignum t len -> Hacl.Bignum.bn_sqr_st t len a
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Hacl.Bignum.Multiplication.bn_sqr", "Prims.unit", "Hacl.Spec.Bignum.bn_sqr_lemma", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let bn_sqr #t len a res =
let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res
false
StRel.fst
StRel.f2_hp
val f2_hp : heap -> ref int -> Tot (heap * int)
val f2_hp : heap -> ref int -> Tot (heap * int)
let f2_hp h x = h, 0
{ "file_name": "examples/rel/StRel.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 28, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module StRel open Rel open FStar.Heap open FStar.ST (* Pure relational reasoning about stateful functions *) (* Pure functions using heap passing *) val f1_hp : heap -> ref int -> GTot (heap * int) let f1_hp h x = h, sel h x
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "StRel.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.Heap.heap -> x: FStar.ST.ref Prims.int -> FStar.Monotonic.Heap.heap * Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.Heap.heap", "FStar.ST.ref", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let f2_hp h x =
h, 0
false
Hacl.Bignum.fst
Hacl.Bignum.bn_karatsuba_mul
val bn_karatsuba_mul: #t:limb_t -> len:size_t{0 < v len /\ 4 * v len <= max_size_t} -> a:lbignum t len -> bn_karatsuba_mul_st t len a
val bn_karatsuba_mul: #t:limb_t -> len:size_t{0 < v len /\ 4 * v len <= max_size_t} -> a:lbignum t len -> bn_karatsuba_mul_st t len a
let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 53, "start_col": 0, "start_line": 50 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t {0 < Lib.IntTypes.v len /\ 4 * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t} -> a: Hacl.Bignum.Definitions.lbignum t len -> Hacl.Bignum.bn_karatsuba_mul_st t len a
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Hacl.Bignum.Karatsuba.bn_karatsuba_mul", "Prims.unit", "Hacl.Spec.Bignum.bn_karatsuba_mul_lemma", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let bn_karatsuba_mul #t len a b res =
let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_mul1_lshift_add_in_place
val bn_mul1_lshift_add_in_place: #t:limb_t -> aLen:size_t -> a:lbignum t aLen -> b:limb t -> resLen:size_t -> j:size_t{v j + v aLen <= v resLen} -> res:lbignum t resLen -> Stack (limb t) (requires fun h -> live h a /\ live h res /\ disjoint res a) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (c_out, as_seq h1 res) == S.bn_mul1_lshift_add (as_seq h0 a) b (v j) (as_seq h0 res))
val bn_mul1_lshift_add_in_place: #t:limb_t -> aLen:size_t -> a:lbignum t aLen -> b:limb t -> resLen:size_t -> j:size_t{v j + v aLen <= v resLen} -> res:lbignum t resLen -> Stack (limb t) (requires fun h -> live h a /\ live h res /\ disjoint res a) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (c_out, as_seq h1 res) == S.bn_mul1_lshift_add (as_seq h0 a) b (v j) (as_seq h0 res))
let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 69, "start_col": 0, "start_line": 68 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
aLen: Lib.IntTypes.size_t -> a: Hacl.Bignum.Definitions.lbignum t aLen -> b: Hacl.Bignum.Definitions.limb t -> resLen: Lib.IntTypes.size_t -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j + Lib.IntTypes.v aLen <= Lib.IntTypes.v resLen} -> res: Hacl.Bignum.Definitions.lbignum t resLen -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Multiplication.bn_mul1_lshift_add", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Pervasives.Native.Mktuple2", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.bn_mul1_lshift_add" ]
[]
false
true
false
false
false
let bn_mul1_lshift_add_in_place #t aLen a b j res =
Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_karatsuba_sqr
val bn_karatsuba_sqr: #t:limb_t -> len:size_t{0 < v len /\ 4 * v len <= max_size_t} -> a:lbignum t len -> bn_karatsuba_sqr_st t len a
val bn_karatsuba_sqr: #t:limb_t -> len:size_t{0 < v len /\ 4 * v len <= max_size_t} -> a:lbignum t len -> bn_karatsuba_sqr_st t len a
let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 61, "start_col": 0, "start_line": 58 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t {0 < Lib.IntTypes.v len /\ 4 * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t} -> a: Hacl.Bignum.Definitions.lbignum t len -> Hacl.Bignum.bn_karatsuba_sqr_st t len a
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Hacl.Bignum.Karatsuba.bn_karatsuba_sqr", "Prims.unit", "Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let bn_karatsuba_sqr #t len a res =
let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_mul1
val bn_mul1: #t:limb_t -> aLen:size_t -> a:lbignum t aLen -> l:limb t -> res:lbignum t aLen -> Stack (limb t) (requires fun h -> live h a /\ live h res /\ eq_or_disjoint res a) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (c_out, as_seq h1 res) == S.bn_mul1 (as_seq h0 a) l)
val bn_mul1: #t:limb_t -> aLen:size_t -> a:lbignum t aLen -> l:limb t -> res:lbignum t aLen -> Stack (limb t) (requires fun h -> live h a /\ live h res /\ eq_or_disjoint res a) (ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\ (c_out, as_seq h1 res) == S.bn_mul1 (as_seq h0 a) l)
let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 48, "start_col": 0, "start_line": 47 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
aLen: Lib.IntTypes.size_t -> a: Hacl.Bignum.Definitions.lbignum t aLen -> l: Hacl.Bignum.Definitions.limb t -> res: Hacl.Bignum.Definitions.lbignum t aLen -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Hacl.Bignum.Multiplication.bn_mul1" ]
[]
false
true
false
false
false
let bn_mul1 #t aLen a l res =
Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_get_bits
val bn_get_bits: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l))
val bn_get_bits: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l))
let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 87, "start_col": 0, "start_line": 86 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> b: Hacl.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_t -> l: Lib.IntTypes.size_t { Lib.IntTypes.v l < Lib.IntTypes.bits t /\ Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len } -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Prims.op_Division", "Hacl.Bignum.Lib.bn_get_bits", "Hacl.Bignum.Definitions.limb" ]
[]
false
true
false
false
false
let bn_get_bits #t len b i l =
Hacl.Bignum.Lib.bn_get_bits len b i l
false
StRel.fst
StRel.glift
val glift : #t:Type -> #t2:Type -> f:(t -> GTot t2) -> rel t -> GTot (rel t2)
val glift : #t:Type -> #t2:Type -> f:(t -> GTot t2) -> rel t -> GTot (rel t2)
let glift #t #t2 f (R x y) = R (f x) (f y)
{ "file_name": "examples/rel/StRel.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 44, "start_col": 0, "start_line": 44 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module StRel open Rel open FStar.Heap open FStar.ST (* Pure relational reasoning about stateful functions *) (* Pure functions using heap passing *) val f1_hp : heap -> ref int -> GTot (heap * int) let f1_hp h x = h, sel h x val f2_hp : heap -> ref int -> Tot (heap * int) let f2_hp h x = h, 0 (* Stateful functions implementing these pure functions *) val f1 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f1_hp h x) == h' /\ snd (f1_hp h x) == r)) let f1 x = !x val f2 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f2_hp h x) == h' /\ snd (f2_hp h x) == r)) let f2 x = 0 val glift : #t:Type -> #t2:Type -> f:(t -> GTot t2) -> rel t
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "StRel.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t -> Prims.GTot t2) -> _: Rel.rel t -> Prims.GTot (Rel.rel t2)
Prims.GTot
[ "sometrivial" ]
[]
[ "Rel.rel", "Rel.R" ]
[]
false
false
false
false
false
let glift #t #t2 f (R x y) =
R (f x) (f y)
false
StRel.fst
StRel.glift2
val glift2 : #t:Type -> #t2:Type -> #t3:Type -> f:(t -> t2 -> GTot t3) -> rel t -> rel t2 -> GTot (rel t3)
val glift2 : #t:Type -> #t2:Type -> #t3:Type -> f:(t -> t2 -> GTot t3) -> rel t -> rel t2 -> GTot (rel t3)
let glift2 #t #t2 #t3 f (R x y) (R x2 y2) = R (f x x2) (f y y2)
{ "file_name": "examples/rel/StRel.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 63, "end_line": 49, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module StRel open Rel open FStar.Heap open FStar.ST (* Pure relational reasoning about stateful functions *) (* Pure functions using heap passing *) val f1_hp : heap -> ref int -> GTot (heap * int) let f1_hp h x = h, sel h x val f2_hp : heap -> ref int -> Tot (heap * int) let f2_hp h x = h, 0 (* Stateful functions implementing these pure functions *) val f1 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f1_hp h x) == h' /\ snd (f1_hp h x) == r)) let f1 x = !x val f2 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f2_hp h x) == h' /\ snd (f2_hp h x) == r)) let f2 x = 0 val glift : #t:Type -> #t2:Type -> f:(t -> GTot t2) -> rel t -> GTot (rel t2) let glift #t #t2 f (R x y) = R (f x) (f y) val glift2 : #t:Type -> #t2:Type -> #t3:Type -> f:(t -> t2 -> GTot t3) -> rel t -> rel t2
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "StRel.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t -> _: t2 -> Prims.GTot t3) -> _: Rel.rel t -> _: Rel.rel t2 -> Prims.GTot (Rel.rel t3)
Prims.GTot
[ "sometrivial" ]
[]
[ "Rel.rel", "FStar.Pervasives.Native.Mktuple2", "Rel.R" ]
[]
false
false
false
false
false
let glift2 #t #t2 #t3 f (R x y) (R x2 y2) =
R (f x x2) (f y y2)
false
Hacl.Spec.FFDHE.Lemmas.fst
Hacl.Spec.FFDHE.Lemmas.ffdhe_p_bits_lemma
val ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma (let ffdhe_p = get_ffdhe_params a in let len = ffdhe_len a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in let p_n = nat_from_bytes_be p in pow2 (8 * len - 1) < p_n)
val ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma (let ffdhe_p = get_ffdhe_params a in let len = ffdhe_len a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in let p_n = nat_from_bytes_be p in pow2 (8 * len - 1) < p_n)
let ffdhe_p_bits_lemma a = let ffdhe_p = get_ffdhe_params a in let len = ffdhe_len a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in let p_n = nat_from_bytes_be p in nat_from_intseq_be_slice_lemma p 1; assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * nat_from_bytes_be (slice p 0 1)); nat_from_intseq_be_lemma0 (slice p 0 1); assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * v p.[0]); assert (pow2 (8 * (len - 1)) * v p.[0] <= p_n); ffdhe_p_lemma_len a; assert (pow2 (8 * (len - 1)) * (pow2 8 - 1) <= p_n); pow2_lt_len len
{ "file_name": "code/ffdhe/Hacl.Spec.FFDHE.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 104, "start_col": 0, "start_line": 91 }
module Hacl.Spec.FFDHE.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.FFDHE #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma (let ffdhe_p = get_ffdhe_params a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in Seq.index p 0 == 0xffuy) let ffdhe_p_lemma_len a = let ffdhe_p = get_ffdhe_params a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in allow_inversion ffdhe_alg; match a with | FFDHE2048 -> assert (p == of_list list_ffdhe_p2048); assert_norm (List.Tot.index list_ffdhe_p2048 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p2048) 0 == 0xffuy) | FFDHE3072 -> assert (p == of_list list_ffdhe_p3072); assert_norm (List.Tot.index list_ffdhe_p3072 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p3072) 0 == 0xffuy) | FFDHE4096 -> assert (p == of_list list_ffdhe_p4096); assert_norm (List.Tot.index list_ffdhe_p4096 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p4096) 0 == 0xffuy) | FFDHE6144 -> assert (p == of_list list_ffdhe_p6144); assert_norm (List.Tot.index list_ffdhe_p6144 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p6144) 0 == 0xffuy) | FFDHE8192 -> assert (p == of_list list_ffdhe_p8192); assert_norm (List.Tot.index list_ffdhe_p8192 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p8192) 0 == 0xffuy) // the proof should be somehow simpler val pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1)) let pow2_lt_len len = let a = pow2 (8 * len - 1) in let b = pow2 (8 * (len - 1)) * (pow2 8 - 1) in calc (==) { b / a; (==) { Math.Lemmas.pow2_plus (8 * len - 8) 7 } b / (pow2 (8 * len - 8) * pow2 7); (==) { Math.Lemmas.division_multiplication_lemma b (pow2 (8 * len - 8)) (pow2 7) } b / pow2 (8 * len - 8) / pow2 7; (==) { Math.Lemmas.cancel_mul_div (pow2 8 - 1) (pow2 (8 * len - 8)) } (pow2 8 - 1) / pow2 7; (==) { Math.Lemmas.pow2_plus 7 1 } (pow2 7 * 2 - 1) / pow2 7; (==) { } 1; }; // assert (b / a * a <= b); // assert (a <= b) calc (>) { pow2 (8 * len - 8) * (pow2 8 - 1) % pow2 (8 * len - 1); (==) { Math.Lemmas.pow2_plus (8 * len - 8) 8 } (pow2 (8 * len) - pow2 (8 * len - 8)) % pow2 (8 * len - 1); (==) { Math.Lemmas.lemma_mod_plus_distr_l (pow2 (8 * len)) (- pow2 (8 * len - 8)) (pow2 (8 * len - 1)) } (pow2 (8 * len) % pow2 (8 * len - 1) - pow2 (8 * len - 8)) % pow2 (8 * len - 1); (==) { Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 (8 * len - 1) (8 * len) } (0 - pow2 (8 * len - 8)) % pow2 (8 * len - 1); //(==) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) } //pow2 (8 * len - 1) - pow2 (8 * len - 8); (>) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) } 0; }; assert (a < b) val ffdhe_p_bits_lemma: a:ffdhe_alg -> Lemma (let ffdhe_p = get_ffdhe_params a in let len = ffdhe_len a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in let p_n = nat_from_bytes_be p in pow2 (8 * len - 1) < p_n)
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.FFDHE.Lemmas.fst" }
[ { "abbrev": false, "full_module": "Spec.FFDHE", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.FFDHE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.FFDHE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.FFDHE.ffdhe_alg -> FStar.Pervasives.Lemma (ensures (let ffdhe_p = Spec.FFDHE.get_ffdhe_params a in let len = Spec.FFDHE.ffdhe_len a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in let p_n = Lib.ByteSequence.nat_from_bytes_be p in Prims.pow2 (8 * len - 1) < p_n))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.FFDHE.ffdhe_alg", "Hacl.Spec.FFDHE.Lemmas.pow2_lt_len", "Prims.unit", "Prims._assert", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Subtraction", "Hacl.Spec.FFDHE.Lemmas.ffdhe_p_lemma_len", "Lib.IntTypes.v", "Lib.IntTypes.U8", "Lib.IntTypes.PUB", "Lib.Sequence.op_String_Access", "Lib.IntTypes.pub_uint8", "Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p_len", "Prims.eq2", "Prims.int", "Prims.op_Addition", "Lib.ByteSequence.nat_from_bytes_be", "Lib.Sequence.slice", "Lib.ByteSequence.nat_from_intseq_be_lemma0", "Lib.ByteSequence.nat_from_intseq_be_slice_lemma", "Prims.nat", "Prims.op_LessThan", "Prims.op_Multiply", "Lib.Sequence.length", "Lib.IntTypes.int_t", "Lib.Sequence.lseq", "Spec.FFDHE.__proj__Mk_ffdhe_params__item__ffdhe_p", "Prims.pos", "Spec.FFDHE.ffdhe_len", "Spec.FFDHE.ffdhe_params_t", "Spec.FFDHE.get_ffdhe_params" ]
[]
true
false
true
false
false
let ffdhe_p_bits_lemma a =
let ffdhe_p = get_ffdhe_params a in let len = ffdhe_len a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in let p_n = nat_from_bytes_be p in nat_from_intseq_be_slice_lemma p 1; assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * nat_from_bytes_be (slice p 0 1)); nat_from_intseq_be_lemma0 (slice p 0 1); assert (p_n == nat_from_bytes_be (slice p 1 len) + pow2 (8 * (len - 1)) * v p.[ 0 ]); assert (pow2 (8 * (len - 1)) * v p.[ 0 ] <= p_n); ffdhe_p_lemma_len a; assert (pow2 (8 * (len - 1)) * (pow2 8 - 1) <= p_n); pow2_lt_len len
false
Hacl.Bignum.fst
Hacl.Bignum.cswap2
val cswap2: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
val cswap2: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 95, "start_col": 0, "start_line": 94 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> bit: Hacl.Bignum.Definitions.limb t -> b1: Hacl.Bignum.Definitions.lbignum t len -> b2: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.limb", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Lib.cswap2_st", "Prims.unit" ]
[]
false
true
false
false
false
let cswap2 #t len bit b1 b2 =
Hacl.Bignum.Lib.cswap2_st len bit b1 b2
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub_mod_n_
val bn_sub_mod_n_ (#t: limb_t) (len: size_t{v len > 0}) : bn_sub_mod_n_st t len
val bn_sub_mod_n_ (#t: limb_t) (len: size_t{v len > 0}) : bn_sub_mod_n_st t len
let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 113, "start_col": 0, "start_line": 110 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_sub_mod_n_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.bn_sub_mod_n_u32", "Hacl.Bignum.bn_sub_mod_n_u64", "Hacl.Bignum.bn_sub_mod_n_st" ]
[]
false
false
false
false
false
let bn_sub_mod_n_ (#t: limb_t) (len: size_t{v len > 0}) : bn_sub_mod_n_st t len =
match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len
false
Hacl.Bignum.fst
Hacl.Bignum.bn_add_mod_n_
val bn_add_mod_n_ (#t: limb_t) (len: size_t{v len > 0}) : bn_add_mod_n_st t len
val bn_add_mod_n_ (#t: limb_t) (len: size_t{v len > 0}) : bn_add_mod_n_st t len
let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 104, "start_col": 0, "start_line": 101 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_add_mod_n_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.bn_add_mod_n_u32", "Hacl.Bignum.bn_add_mod_n_u64", "Hacl.Bignum.bn_add_mod_n_st" ]
[]
false
false
false
false
false
let bn_add_mod_n_ (#t: limb_t) (len: size_t{v len > 0}) : bn_add_mod_n_st t len =
match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len
false
StRel.fst
StRel.f1
val f1 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f1_hp h x) == h' /\ snd (f1_hp h x) == r))
val f1 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f1_hp h x) == h' /\ snd (f1_hp h x) == r))
let f1 x = !x
{ "file_name": "examples/rel/StRel.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 34, "start_col": 0, "start_line": 34 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module StRel open Rel open FStar.Heap open FStar.ST (* Pure relational reasoning about stateful functions *) (* Pure functions using heap passing *) val f1_hp : heap -> ref int -> GTot (heap * int) let f1_hp h x = h, sel h x val f2_hp : heap -> ref int -> Tot (heap * int) let f2_hp h x = h, 0 (* Stateful functions implementing these pure functions *) val f1 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f1_hp h x) == h'
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "StRel.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.ST.ref Prims.int -> FStar.ST.ST Prims.int
FStar.ST.ST
[]
[]
[ "FStar.ST.ref", "Prims.int", "FStar.ST.op_Bang", "FStar.Heap.trivial_preorder" ]
[]
false
true
false
false
false
let f1 x =
!x
false
StRel.fst
StRel.f2
val f2 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f2_hp h x) == h' /\ snd (f2_hp h x) == r))
val f2 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f2_hp h x) == h' /\ snd (f2_hp h x) == r))
let f2 x = 0
{ "file_name": "examples/rel/StRel.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 39, "start_col": 0, "start_line": 39 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module StRel open Rel open FStar.Heap open FStar.ST (* Pure relational reasoning about stateful functions *) (* Pure functions using heap passing *) val f1_hp : heap -> ref int -> GTot (heap * int) let f1_hp h x = h, sel h x val f2_hp : heap -> ref int -> Tot (heap * int) let f2_hp h x = h, 0 (* Stateful functions implementing these pure functions *) val f1 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f1_hp h x) == h' /\ snd (f1_hp h x) == r)) let f1 x = !x val f2 : x:(ref int) -> ST int (requires (fun h -> True)) (ensures (fun h r h' -> fst (f2_hp h x) == h'
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "FStar.ST.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Heap.fst.checked" ], "interface_file": false, "source_file": "StRel.fst" }
[ { "abbrev": false, "full_module": "FStar.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Heap", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.ST.ref Prims.int -> FStar.ST.ST Prims.int
FStar.ST.ST
[]
[]
[ "FStar.ST.ref", "Prims.int" ]
[]
false
true
false
false
false
let f2 x =
0
false
Hacl.Bignum.fst
Hacl.Bignum.bn_rshift
val bn_rshift: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i < v len} -> res:lbignum t (len -! i) -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_rshift (as_seq h0 b) (v i))
val bn_rshift: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i < v len} -> res:lbignum t (len -! i) -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_rshift (as_seq h0 b) (v i))
let bn_rshift #t len b i res = copy res (sub b i (len -! i))
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 72, "start_col": 0, "start_line": 71 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> b: Hacl.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v len} -> res: Hacl.Bignum.Definitions.lbignum t (len -! i) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.op_Subtraction_Bang", "Lib.Buffer.copy", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Prims.unit", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.sub", "Lib.Buffer.sub" ]
[]
false
true
false
false
false
let bn_rshift #t len b i res =
copy res (sub b i (len -! i))
false
Hacl.Bignum.fst
Hacl.Bignum.bn_eq_mask
val bn_eq_mask: #t:limb_t -> len:size_t -> bn_eq_mask_st t len
val bn_eq_mask: #t:limb_t -> len:size_t -> bn_eq_mask_st t len
let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 136, "start_col": 0, "start_line": 135 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> Hacl.Bignum.bn_eq_mask_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Comparison.bn_eq_mask", "Hacl.Bignum.Definitions.limb" ]
[]
false
false
false
false
false
let bn_eq_mask #t len a b =
Hacl.Bignum.Comparison.bn_eq_mask len a b
false
Hacl.Bignum.fst
Hacl.Bignum.bn_is_odd
val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a))
val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a))
let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 133, "start_col": 0, "start_line": 132 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> a: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Comparison.bn_is_odd", "Hacl.Bignum.Definitions.limb" ]
[]
false
true
false
false
false
let bn_is_odd #t len a =
Hacl.Bignum.Comparison.bn_is_odd len a
false
Hacl.Bignum.fst
Hacl.Bignum.bn_set_ith_bit
val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 90, "start_col": 0, "start_line": 89 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> b: Hacl.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Hacl.Bignum.Lib.bn_set_ith_bit", "Prims.unit" ]
[]
false
true
false
false
false
let bn_set_ith_bit #t len input ind =
Hacl.Bignum.Lib.bn_set_ith_bit len input ind
false
Hacl.Bignum.fst
Hacl.Bignum.bn_lt_mask
val bn_lt_mask: #t:limb_t -> len:size_t -> bn_lt_mask_st t len
val bn_lt_mask: #t:limb_t -> len:size_t -> bn_lt_mask_st t len
let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 142, "start_col": 0, "start_line": 141 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> Hacl.Bignum.bn_lt_mask_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Comparison.bn_lt_mask", "Hacl.Bignum.Definitions.limb" ]
[]
false
false
false
false
false
let bn_lt_mask #t len a b =
Hacl.Bignum.Comparison.bn_lt_mask len a b
false
Hacl.Bignum.fst
Hacl.Bignum.bn_reduce_once
val bn_reduce_once: #t:limb_t -> aLen:size_t{v aLen > 0} -> n:lbignum t aLen -> c:carry t -> a:lbignum t aLen -> Stack unit (requires fun h -> live h a /\ live h n /\ disjoint a n) (ensures fun h0 c_out h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_reduce_once (as_seq h0 n) c (as_seq h0 a))
val bn_reduce_once: #t:limb_t -> aLen:size_t{v aLen > 0} -> n:lbignum t aLen -> c:carry t -> a:lbignum t aLen -> Stack unit (requires fun h -> live h a /\ live h n /\ disjoint a n) (ensures fun h0 c_out h1 -> modifies (loc a) h0 h1 /\ as_seq h1 a == S.bn_reduce_once (as_seq h0 n) c (as_seq h0 a))
let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame()
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 31, "start_col": 0, "start_line": 25 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
aLen: Lib.IntTypes.size_t{Lib.IntTypes.v aLen > 0} -> n: Hacl.Bignum.Definitions.lbignum t aLen -> c: Hacl.Spec.Bignum.Base.carry t -> a: Hacl.Bignum.Definitions.lbignum t aLen -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.carry", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.map2T", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.mask_select", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Hacl.Bignum.bn_sub_eq_len", "Lib.Buffer.lbuffer_t", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_reduce_once #t len n c0 res =
push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame ()
false
Hacl.Bignum.fst
Hacl.Bignum.mk_runtime_bn
val mk_runtime_bn: t:limb_t -> len:meta_len t -> bn t
val mk_runtime_bn: t:limb_t -> len:meta_len t -> bn t
let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; }
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 1, "end_line": 126, "start_col": 0, "start_line": 118 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Hacl.Bignum.bn t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Mkbn", "Hacl.Bignum.Addition.bn_add_eq_len_u", "Hacl.Bignum.Addition.bn_sub_eq_len_u", "Hacl.Bignum.bn_add_mod_n_", "Hacl.Bignum.bn_sub_mod_n_", "Hacl.Bignum.bn_karatsuba_mul", "Hacl.Bignum.bn_karatsuba_sqr", "Hacl.Bignum.bn" ]
[]
false
false
false
false
false
let mk_runtime_bn (t: limb_t) (len: meta_len t) : bn t =
{ len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len }
false
Hacl.Bignum.fst
Hacl.Bignum.bn_is_zero_mask
val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a))
val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a))
let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 139, "start_col": 0, "start_line": 138 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> a: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Comparison.bn_is_zero_mask", "Hacl.Bignum.Definitions.limb" ]
[]
false
true
false
false
false
let bn_is_zero_mask #t len b =
Hacl.Bignum.Comparison.bn_is_zero_mask len b
false
Hacl.Bignum.fst
Hacl.Bignum.bn_get_ith_bit
val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i))
val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 84, "start_col": 0, "start_line": 83 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> b: Hacl.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Hacl.Bignum.Lib.bn_get_ith_bit", "Hacl.Bignum.Definitions.limb" ]
[]
false
true
false
false
false
let bn_get_ith_bit #t len input ind =
Hacl.Bignum.Lib.bn_get_ith_bit len input ind
false
Hacl.Bignum.fst
Hacl.Bignum.bn_lt_pow2_mask
val bn_lt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_pow2_mask (as_seq h0 b) (v x))
val bn_lt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_pow2_mask (as_seq h0 b) (v x))
let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 145, "start_col": 0, "start_line": 144 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.bits t * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> b: Hacl.Bignum.Definitions.lbignum t len -> x: Lib.IntTypes.size_t{Lib.IntTypes.v x < Lib.IntTypes.bits t * Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Comparison.bn_lt_pow2_mask", "Hacl.Bignum.Definitions.limb" ]
[]
false
true
false
false
false
let bn_lt_pow2_mask #t len b x =
Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x
false
Hacl.Bignum.fst
Hacl.Bignum.bn_gt_pow2_mask
val bn_gt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_gt_pow2_mask (as_seq h0 b) (v x))
val bn_gt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_gt_pow2_mask (as_seq h0 b) (v x))
let bn_gt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 148, "start_col": 0, "start_line": 147 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.bits t * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> b: Hacl.Bignum.Definitions.lbignum t len -> x: Lib.IntTypes.size_t{Lib.IntTypes.v x < Lib.IntTypes.bits t * Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Comparison.bn_gt_pow2_mask", "Hacl.Bignum.Definitions.limb" ]
[]
false
true
false
false
false
let bn_gt_pow2_mask #t len b x =
Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x
false
Hacl.Spec.FFDHE.Lemmas.fst
Hacl.Spec.FFDHE.Lemmas.pow2_lt_len
val pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1))
val pow2_lt_len: len:size_pos -> Lemma (pow2 (8 * len - 1) < pow2 (8 * (len - 1)) * (pow2 8 - 1))
let pow2_lt_len len = let a = pow2 (8 * len - 1) in let b = pow2 (8 * (len - 1)) * (pow2 8 - 1) in calc (==) { b / a; (==) { Math.Lemmas.pow2_plus (8 * len - 8) 7 } b / (pow2 (8 * len - 8) * pow2 7); (==) { Math.Lemmas.division_multiplication_lemma b (pow2 (8 * len - 8)) (pow2 7) } b / pow2 (8 * len - 8) / pow2 7; (==) { Math.Lemmas.cancel_mul_div (pow2 8 - 1) (pow2 (8 * len - 8)) } (pow2 8 - 1) / pow2 7; (==) { Math.Lemmas.pow2_plus 7 1 } (pow2 7 * 2 - 1) / pow2 7; (==) { } 1; }; // assert (b / a * a <= b); // assert (a <= b) calc (>) { pow2 (8 * len - 8) * (pow2 8 - 1) % pow2 (8 * len - 1); (==) { Math.Lemmas.pow2_plus (8 * len - 8) 8 } (pow2 (8 * len) - pow2 (8 * len - 8)) % pow2 (8 * len - 1); (==) { Math.Lemmas.lemma_mod_plus_distr_l (pow2 (8 * len)) (- pow2 (8 * len - 8)) (pow2 (8 * len - 1)) } (pow2 (8 * len) % pow2 (8 * len - 1) - pow2 (8 * len - 8)) % pow2 (8 * len - 1); (==) { Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 (8 * len - 1) (8 * len) } (0 - pow2 (8 * len - 8)) % pow2 (8 * len - 1); //(==) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) } //pow2 (8 * len - 1) - pow2 (8 * len - 8); (>) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) } 0; }; assert (a < b)
{ "file_name": "code/ffdhe/Hacl.Spec.FFDHE.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 81, "start_col": 0, "start_line": 48 }
module Hacl.Spec.FFDHE.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.FFDHE #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val ffdhe_p_lemma_len: a:ffdhe_alg -> Lemma (let ffdhe_p = get_ffdhe_params a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in Seq.index p 0 == 0xffuy) let ffdhe_p_lemma_len a = let ffdhe_p = get_ffdhe_params a in let p = Mk_ffdhe_params?.ffdhe_p ffdhe_p in allow_inversion ffdhe_alg; match a with | FFDHE2048 -> assert (p == of_list list_ffdhe_p2048); assert_norm (List.Tot.index list_ffdhe_p2048 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p2048) 0 == 0xffuy) | FFDHE3072 -> assert (p == of_list list_ffdhe_p3072); assert_norm (List.Tot.index list_ffdhe_p3072 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p3072) 0 == 0xffuy) | FFDHE4096 -> assert (p == of_list list_ffdhe_p4096); assert_norm (List.Tot.index list_ffdhe_p4096 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p4096) 0 == 0xffuy) | FFDHE6144 -> assert (p == of_list list_ffdhe_p6144); assert_norm (List.Tot.index list_ffdhe_p6144 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p6144) 0 == 0xffuy) | FFDHE8192 -> assert (p == of_list list_ffdhe_p8192); assert_norm (List.Tot.index list_ffdhe_p8192 0 == 0xffuy); assert (Seq.index (Seq.seq_of_list list_ffdhe_p8192) 0 == 0xffuy) // the proof should be somehow simpler
{ "checked_file": "/", "dependencies": [ "Spec.FFDHE.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.FFDHE.Lemmas.fst" }
[ { "abbrev": false, "full_module": "Spec.FFDHE", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.FFDHE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.FFDHE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_pos -> FStar.Pervasives.Lemma (ensures Prims.pow2 (8 * len - 1) < Prims.pow2 (8 * (len - 1)) * (Prims.pow2 8 - 1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.size_pos", "Prims._assert", "Prims.b2t", "Prims.op_LessThan", "Prims.unit", "FStar.Calc.calc_finish", "Prims.int", "Prims.op_GreaterThan", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.eq2", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.pow2_plus", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Prims.op_Minus", "FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_1", "FStar.Math.Lemmas.pow2_lt_compat", "Prims.op_Division", "FStar.Math.Lemmas.division_multiplication_lemma", "FStar.Math.Lemmas.cancel_mul_div", "Prims.pos" ]
[]
false
false
true
false
false
let pow2_lt_len len =
let a = pow2 (8 * len - 1) in let b = pow2 (8 * (len - 1)) * (pow2 8 - 1) in calc ( == ) { b / a; ( == ) { Math.Lemmas.pow2_plus (8 * len - 8) 7 } b / (pow2 (8 * len - 8) * pow2 7); ( == ) { Math.Lemmas.division_multiplication_lemma b (pow2 (8 * len - 8)) (pow2 7) } b / pow2 (8 * len - 8) / pow2 7; ( == ) { Math.Lemmas.cancel_mul_div (pow2 8 - 1) (pow2 (8 * len - 8)) } (pow2 8 - 1) / pow2 7; ( == ) { Math.Lemmas.pow2_plus 7 1 } (pow2 7 * 2 - 1) / pow2 7; ( == ) { () } 1; }; calc ( > ) { pow2 (8 * len - 8) * (pow2 8 - 1) % pow2 (8 * len - 1); ( == ) { Math.Lemmas.pow2_plus (8 * len - 8) 8 } (pow2 (8 * len) - pow2 (8 * len - 8)) % pow2 (8 * len - 1); ( == ) { Math.Lemmas.lemma_mod_plus_distr_l (pow2 (8 * len)) (- pow2 (8 * len - 8)) (pow2 (8 * len - 1)) } (pow2 (8 * len) % pow2 (8 * len - 1) - pow2 (8 * len - 8)) % pow2 (8 * len - 1); ( == ) { Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 (8 * len - 1) (8 * len) } (0 - pow2 (8 * len - 8)) % pow2 (8 * len - 1); ( > ) { Math.Lemmas.pow2_lt_compat (8 * len - 1) (8 * len - 8) } 0; }; assert (a < b)
false
Hacl.Bignum.fst
Hacl.Bignum.bn_from_uint
val bn_from_uint: #t:limb_t -> len:size_t{0 < v len} -> x:limb t -> b:lbignum t len -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_from_uint (v len) x)
val bn_from_uint: #t:limb_t -> len:size_t{0 < v len} -> x:limb t -> b:lbignum t len -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_from_uint (v len) x)
let bn_from_uint #t len x b = Hacl.Bignum.Convert.bn_from_uint len x b
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 153, "start_col": 0, "start_line": 152 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x let bn_gt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x (* Convertion functions *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> x: Hacl.Bignum.Definitions.limb t -> b: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.limb", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Convert.bn_from_uint", "Prims.unit" ]
[]
false
true
false
false
false
let bn_from_uint #t len x b =
Hacl.Bignum.Convert.bn_from_uint len x b
false
Hacl.Impl.Ed25519.Ladder.fst
Hacl.Impl.Ed25519.Ladder.point_mul_g_double_vartime_aux
val point_mul_g_double_vartime_aux: out:point -> scalar1:lbuffer uint8 32ul -> q1:point -> scalar2:lbuffer uint8 32ul -> q2:point -> bscalar1:lbuffer uint64 4ul -> bscalar2:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h bscalar1 /\ live h bscalar2 /\ disjoint scalar1 bscalar1 /\ disjoint scalar2 bscalar2 /\ disjoint scalar2 bscalar1 /\ disjoint scalar1 bscalar2 /\ disjoint bscalar1 bscalar2 /\ disjoint bscalar1 out /\ disjoint bscalar1 q1 /\ disjoint bscalar1 q2 /\ disjoint bscalar2 out /\ disjoint bscalar2 q1 /\ disjoint bscalar2 q2 /\ eq_or_disjoint q1 q2 /\ disjoint q1 out /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out |+| loc bscalar1 |+| loc bscalar2) h0 h1 /\ F51.linv (as_seq h1 out) /\ BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1) /\ BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h1 bscalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h1 bscalar2) 5)
val point_mul_g_double_vartime_aux: out:point -> scalar1:lbuffer uint8 32ul -> q1:point -> scalar2:lbuffer uint8 32ul -> q2:point -> bscalar1:lbuffer uint64 4ul -> bscalar2:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h bscalar1 /\ live h bscalar2 /\ disjoint scalar1 bscalar1 /\ disjoint scalar2 bscalar2 /\ disjoint scalar2 bscalar1 /\ disjoint scalar1 bscalar2 /\ disjoint bscalar1 bscalar2 /\ disjoint bscalar1 out /\ disjoint bscalar1 q1 /\ disjoint bscalar1 q2 /\ disjoint bscalar2 out /\ disjoint bscalar2 q1 /\ disjoint bscalar2 q2 /\ eq_or_disjoint q1 q2 /\ disjoint q1 out /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out |+| loc bscalar1 |+| loc bscalar2) h0 h1 /\ F51.linv (as_seq h1 out) /\ BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1) /\ BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h1 bscalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h1 bscalar2) 5)
let point_mul_g_double_vartime_aux out scalar1 q1 scalar2 q2 bscalar1 bscalar2 = let h0 = ST.get () in convert_scalar scalar1 bscalar1; convert_scalar scalar2 bscalar2; let h1 = ST.get () in assert (BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1)); assert (BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2)); point_mul_g_double_vartime_table out bscalar1 q1 bscalar2 q2
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Ladder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 374, "start_col": 0, "start_line": 367 }
module Hacl.Impl.Ed25519.Ladder module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module BSeq = Lib.ByteSequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module ME = Hacl.Impl.MultiExponentiation module PT = Hacl.Impl.PrecompTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module BD = Hacl.Bignum.Definitions module SD = Hacl.Spec.Bignum.Definitions module S = Spec.Ed25519 open Hacl.Impl.Ed25519.PointConstants include Hacl.Impl.Ed25519.Group include Hacl.Ed25519.PrecompTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let table_inv_w4 : BE.table_inv_t U64 20ul 16ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract let table_inv_w5 : BE.table_inv_t U64 20ul 32ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in assert_norm (pow2 (v l) = v table_len); BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract val convert_scalar: scalar:lbuffer uint8 32ul -> bscalar:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h scalar /\ live h bscalar /\ disjoint scalar bscalar) (ensures fun h0 _ h1 -> modifies (loc bscalar) h0 h1 /\ BD.bn_v h1 bscalar == BSeq.nat_from_bytes_le (as_seq h0 scalar)) let convert_scalar scalar bscalar = let h0 = ST.get () in Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #U64 32 (as_seq h0 scalar); Hacl.Bignum.Convert.mk_bn_from_bytes_le true 32ul scalar bscalar inline_for_extraction noextract val point_mul_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q:point -> Stack unit (requires fun h -> live h bscalar /\ live h q /\ live h out /\ disjoint q out /\ disjoint q bscalar /\ disjoint out bscalar /\ F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q) /\ BD.bn_v h bscalar < pow2 256) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_fw S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q)) 256 (BD.bn_v h0 bscalar) 4) let point_mul_noalloc out bscalar q = BE.lexp_fw_consttime 20ul 0ul mk_ed25519_concrete_ops 4ul (null uint64) q 4ul 256ul bscalar out let point_mul out scalar q = let h0 = ST.get () in SE.exp_fw_lemma S.mk_ed25519_concrete_ops (F51.point_eval h0 q) 256 (BSeq.nat_from_bytes_le (as_seq h0 scalar)) 4; push_frame (); let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; point_mul_noalloc out bscalar q; pop_frame () val precomp_get_consttime: BE.pow_a_to_small_b_st U64 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul (BE.table_inv_precomp 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul) [@CInline] let precomp_get_consttime ctx a table bits_l tmp = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.lprecomp_get_consttime len ctx_len k l table_len ctx a table bits_l tmp inline_for_extraction noextract val point_mul_g_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> q2:point -> q3:point -> q4:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ live h q2 /\ live h q3 /\ live h q4 /\ disjoint out bscalar /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out q3 /\ disjoint out q4 /\ disjoint q1 q2 /\ disjoint q1 q3 /\ disjoint q1 q4 /\ disjoint q2 q3 /\ disjoint q2 q4 /\ disjoint q3 q4 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff /\ F51.linv (as_seq h q2) /\ refl (as_seq h q2) == g_pow2_64 /\ F51.linv (as_seq h q3) /\ refl (as_seq h q3) == g_pow2_128 /\ F51.linv (as_seq h q4) /\ refl (as_seq h q4) == g_pow2_192) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_noalloc out bscalar q1 q2 q3 q4 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in [@inline_let] let bLen = 1ul in [@inline_let] let bBits = 64ul in let h0 = ST.get () in recall_contents precomp_basepoint_table_w4 precomp_basepoint_table_lseq_w4; let h1 = ST.get () in precomp_basepoint_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w4)); recall_contents precomp_g_pow2_64_table_w4 precomp_g_pow2_64_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_64_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q2) (as_seq h1 precomp_g_pow2_64_table_w4)); recall_contents precomp_g_pow2_128_table_w4 precomp_g_pow2_128_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_128_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q3) (as_seq h1 precomp_g_pow2_128_table_w4)); recall_contents precomp_g_pow2_192_table_w4 precomp_g_pow2_192_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_192_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q4) (as_seq h1 precomp_g_pow2_192_table_w4)); let r1 = sub bscalar 0ul 1ul in let r2 = sub bscalar 1ul 1ul in let r3 = sub bscalar 2ul 1ul in let r4 = sub bscalar 3ul 1ul in SPT256.lemma_decompose_nat256_as_four_u64_lbignum (as_seq h0 bscalar); ME.mk_lexp_four_fw_tables len ctx_len k l table_len table_inv_w4 table_inv_w4 table_inv_w4 table_inv_w4 precomp_get_consttime precomp_get_consttime precomp_get_consttime precomp_get_consttime (null uint64) q1 bLen bBits r1 q2 r2 q3 r3 q4 r4 (to_const precomp_basepoint_table_w4) (to_const precomp_g_pow2_64_table_w4) (to_const precomp_g_pow2_128_table_w4) (to_const precomp_g_pow2_192_table_w4) out; LowStar.Ignore.ignore q2; // q2, q3, q4 are unused variables LowStar.Ignore.ignore q3; LowStar.Ignore.ignore q4 inline_for_extraction noextract val point_mul_g_mk_q1234: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ disjoint out bscalar /\ disjoint out q1 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_mk_q1234 out bscalar q1 = push_frame (); let q2 = mk_ext_g_pow2_64 () in let q3 = mk_ext_g_pow2_128 () in let q4 = mk_ext_g_pow2_192 () in ext_g_pow2_64_lseq_lemma (); ext_g_pow2_128_lseq_lemma (); ext_g_pow2_192_lseq_lemma (); point_mul_g_noalloc out bscalar q1 q2 q3 q4; pop_frame () val lemma_exp_four_fw_local: b:BSeq.lbytes 32 -> Lemma (let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 == S.to_aff_point (S.point_mul_g b)) let lemma_exp_four_fw_local b = let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in let res = LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 in assert (res == SPT256.exp_as_exp_four_nat256_precomp cm g_aff bn); SPT256.lemma_point_mul_base_precomp4 cm g_aff bn; assert (res == LE.pow cm g_aff bn); SE.exp_fw_lemma S.mk_ed25519_concrete_ops g_c 256 bn 4; LE.exp_fw_lemma cm g_aff 256 bn 4; assert (S.to_aff_point (S.point_mul_g b) == LE.pow cm g_aff bn) [@CInline] let point_mul_g out scalar = push_frame (); let h0 = ST.get () in let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; let q1 = create 20ul (u64 0) in make_g q1; point_mul_g_mk_q1234 out bscalar q1; lemma_exp_four_fw_local (as_seq h0 scalar); pop_frame () inline_for_extraction noextract val point_mul_g_double_vartime_noalloc: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> table2: lbuffer uint64 640ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h table2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ disjoint out table2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c /\ table_inv_w5 (as_seq h q2) (as_seq h table2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5) let point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in [@inline_let] let bLen = 4ul in [@inline_let] let bBits = 256ul in assert_norm (pow2 (v l) == v table_len); let h0 = ST.get () in recall_contents precomp_basepoint_table_w5 precomp_basepoint_table_lseq_w5; let h1 = ST.get () in precomp_basepoint_table_lemma_w5 (); assert (table_inv_w5 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w5)); assert (table_inv_w5 (as_seq h1 q2) (as_seq h1 table2)); ME.mk_lexp_double_fw_tables len ctx_len k l table_len table_inv_w5 table_inv_w5 (BE.lprecomp_get_vartime len ctx_len k l table_len) (BE.lprecomp_get_vartime len ctx_len k l table_len) (null uint64) q1 bLen bBits scalar1 q2 scalar2 (to_const precomp_basepoint_table_w5) (to_const table2) out inline_for_extraction noextract val point_mul_g_double_vartime_table: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5) let point_mul_g_double_vartime_table out scalar1 q1 scalar2 q2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let table_len = 32ul in assert_norm (pow2 5 == v table_len); push_frame (); let table2 = create (table_len *! len) (u64 0) in PT.lprecomp_table len ctx_len k (null uint64) q2 table_len table2; point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2; pop_frame () inline_for_extraction noextract val point_mul_g_double_vartime_aux: out:point -> scalar1:lbuffer uint8 32ul -> q1:point -> scalar2:lbuffer uint8 32ul -> q2:point -> bscalar1:lbuffer uint64 4ul -> bscalar2:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h bscalar1 /\ live h bscalar2 /\ disjoint scalar1 bscalar1 /\ disjoint scalar2 bscalar2 /\ disjoint scalar2 bscalar1 /\ disjoint scalar1 bscalar2 /\ disjoint bscalar1 bscalar2 /\ disjoint bscalar1 out /\ disjoint bscalar1 q1 /\ disjoint bscalar1 q2 /\ disjoint bscalar2 out /\ disjoint bscalar2 q1 /\ disjoint bscalar2 q2 /\ eq_or_disjoint q1 q2 /\ disjoint q1 out /\ disjoint q2 out /\ disjoint scalar1 out /\ disjoint scalar2 out /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c) (ensures fun h0 _ h1 -> modifies (loc out |+| loc bscalar1 |+| loc bscalar2) h0 h1 /\ F51.linv (as_seq h1 out) /\ BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1) /\ BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h1 bscalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h1 bscalar2) 5)
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.MultiExponentiation.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "Hacl.Impl.Ed25519.PointNegate.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.Group.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Ed25519.PrecompTable.fsti.checked", "Hacl.Bignum25519.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.Ed25519.Ladder.fst" }
[ { "abbrev": false, "full_module": "Hacl.Ed25519.PrecompTable", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Impl.MultiExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Bignum25519.point -> scalar1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> q1: Hacl.Bignum25519.point -> scalar2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> q2: Hacl.Bignum25519.point -> bscalar1: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> bscalar2: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint64", "Hacl.Impl.Ed25519.Ladder.point_mul_g_double_vartime_table", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.Bignum.Definitions.bn_v", "Lib.IntTypes.U64", "Lib.ByteSequence.nat_from_bytes_le", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Ed25519.Ladder.convert_scalar" ]
[]
false
true
false
false
false
let point_mul_g_double_vartime_aux out scalar1 q1 scalar2 q2 bscalar1 bscalar2 =
let h0 = ST.get () in convert_scalar scalar1 bscalar1; convert_scalar scalar2 bscalar2; let h1 = ST.get () in assert (BD.bn_v h1 bscalar1 == BSeq.nat_from_bytes_le (as_seq h0 scalar1)); assert (BD.bn_v h1 bscalar2 == BSeq.nat_from_bytes_le (as_seq h0 scalar2)); point_mul_g_double_vartime_table out bscalar1 q1 bscalar2 q2
false
Hacl.Bignum.fst
Hacl.Bignum.bn_sub_mod_n
val bn_sub_mod_n: #t:limb_t -> len:size_t{v len > 0} -> bn_sub_mod_n_st t len
val bn_sub_mod_n: #t:limb_t -> len:size_t{v len > 0} -> bn_sub_mod_n_st t len
let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame ()
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 45, "start_col": 0, "start_line": 37 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Hacl.Bignum.bn_sub_mod_n_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.map2T", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.mask_select", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint", "LowStar.Ignore.ignore", "Hacl.Spec.Bignum.Base.carry", "Hacl.Bignum.bn_add_eq_len", "Lib.Buffer.lbuffer_t", "Lib.Buffer.create", "Lib.Buffer.lbuffer", "Hacl.Bignum.bn_sub_eq_len", "FStar.HyperStack.ST.push_frame" ]
[]
false
false
false
false
false
let bn_sub_mod_n #t len n a b res =
push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame ()
false
Hacl.Bignum.fst
Hacl.Bignum.bn_to_bytes_le
val bn_to_bytes_le: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbignum t (blocks len (size (numbytes t))) -> res:lbuffer uint8 len -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b))
val bn_to_bytes_le: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbignum t (blocks len (size (numbytes t))) -> res:lbuffer uint8 len -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_to_bytes_le (v len) (as_seq h0 b))
let bn_to_bytes_le #t len b res = Hacl.Bignum.Convert.bn_to_bytes_le len b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 165, "start_col": 0, "start_line": 164 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x let bn_gt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x (* Convertion functions *) let bn_from_uint #t len x b = Hacl.Bignum.Convert.bn_from_uint len x b let bn_from_bytes_be #t len b res = Hacl.Bignum.Convert.bn_from_bytes_be len b res let bn_to_bytes_be #t len b res = Hacl.Bignum.Convert.bn_to_bytes_be len b res let bn_from_bytes_le #t len b res = Hacl.Bignum.Convert.bn_from_bytes_le len b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.numbytes t * Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <= Lib.IntTypes.max_size_t } -> b: Hacl.Bignum.Definitions.lbignum t (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) -> res: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Bignum.Convert.bn_to_bytes_le", "Prims.unit" ]
[]
false
true
false
false
false
let bn_to_bytes_le #t len b res =
Hacl.Bignum.Convert.bn_to_bytes_le len b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_from_bytes_be
val bn_from_bytes_be: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbuffer uint8 len -> res:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
val bn_from_bytes_be: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbuffer uint8 len -> res:lbignum t (blocks len (size (numbytes t))) -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_from_bytes_be (v len) (as_seq h0 b))
let bn_from_bytes_be #t len b res = Hacl.Bignum.Convert.bn_from_bytes_be len b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 156, "start_col": 0, "start_line": 155 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x let bn_gt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x (* Convertion functions *) let bn_from_uint #t len x b = Hacl.Bignum.Convert.bn_from_uint len x b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.numbytes t * Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <= Lib.IntTypes.max_size_t } -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> res: Hacl.Bignum.Definitions.lbignum t (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Convert.bn_from_bytes_be", "Prims.unit" ]
[]
false
true
false
false
false
let bn_from_bytes_be #t len b res =
Hacl.Bignum.Convert.bn_from_bytes_be len b res
false
Hacl.Bignum.fst
Hacl.Bignum.bn_to_bytes_be
val bn_to_bytes_be: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbignum t (blocks len (size (numbytes t))) -> res:lbuffer uint8 len -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
val bn_to_bytes_be: #t:limb_t -> len:size_t{0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t} -> b:lbignum t (blocks len (size (numbytes t))) -> res:lbuffer uint8 len -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint res b) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.bn_to_bytes_be (v len) (as_seq h0 b))
let bn_to_bytes_be #t len b res = Hacl.Bignum.Convert.bn_to_bytes_be len b res
{ "file_name": "code/bignum/Hacl.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 159, "start_col": 0, "start_line": 158 }
module Hacl.Bignum friend Hacl.Spec.Bignum #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_add1 aLen a b1 res let bn_sub1 #t aLen a b1 res = Hacl.Bignum.Addition.bn_sub1 aLen a b1 res let bn_add_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_add_eq_len aLen a b res let bn_sub_eq_len #t aLen a b res = Hacl.Bignum.Addition.bn_sub_eq_len aLen a b res let bn_add #t aLen a bLen b res = Hacl.Bignum.Addition.bn_add aLen a bLen b res let bn_sub #t aLen a bLen b res = Hacl.Bignum.Addition.bn_sub aLen a bLen b res let bn_reduce_once #t len n c0 res = push_frame (); let tmp = create len (uint #t 0) in let c1 = bn_sub_eq_len len res n tmp in let c = c0 -. c1 in map2T len res (mask_select c) res tmp; pop_frame() let bn_add_mod_n #t len n a b res = let c0 = bn_add_eq_len len a b res in bn_reduce_once len n c0 res let bn_sub_mod_n #t len n a b res = push_frame (); let c0 = bn_sub_eq_len len a b res in let tmp = create len (uint #t 0) in let c1 = bn_add_eq_len len res n tmp in LowStar.Ignore.ignore c1; let c = uint #t 0 -. c0 in map2T len res (mask_select c) tmp res; pop_frame () let bn_mul1 #t aLen a l res = Hacl.Bignum.Multiplication.bn_mul1 #t aLen a l res let bn_karatsuba_mul #t len a b res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_mul_lemma (as_seq h0 a) (as_seq h0 b); Hacl.Bignum.Karatsuba.bn_karatsuba_mul len a b res let bn_mul #t aLen bLen a b res = Hacl.Bignum.Multiplication.bn_mul aLen a bLen b res let bn_karatsuba_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma (as_seq h0 a); Hacl.Bignum.Karatsuba.bn_karatsuba_sqr len a res let bn_sqr #t len a res = let h0 = ST.get () in Hacl.Spec.Bignum.bn_sqr_lemma (as_seq h0 a); Hacl.Bignum.Multiplication.bn_sqr len a res let bn_mul1_lshift_add_in_place #t aLen a b j res = Hacl.Bignum.Multiplication.bn_mul1_lshift_add aLen a b j res let bn_rshift #t len b i res = copy res (sub b i (len -! i)) let bn_sub_mask #t len n a = push_frame (); let mask = create 1ul (ones t SEC) in let mod_mask = create len (uint #t 0) in let mask = Lib.ByteBuffer.buf_eq_mask n a len mask in mapT len mod_mask (logand mask) n; let _ = Hacl.Bignum.Addition.bn_sub_eq_len len a mod_mask a in pop_frame () let bn_get_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_get_ith_bit len input ind let bn_get_bits #t len b i l = Hacl.Bignum.Lib.bn_get_bits len b i l let bn_set_ith_bit #t len input ind = Hacl.Bignum.Lib.bn_set_ith_bit len input ind (* conditional swap *) let cswap2 #t len bit b1 b2 = Hacl.Bignum.Lib.cswap2_st len bit b1 b2 let bn_add_mod_n_u32 (len:size_t{v len > 0}) : bn_add_mod_n_st U32 len = bn_add_mod_n len let bn_add_mod_n_u64 (len:size_t{v len > 0}) : bn_add_mod_n_st U64 len = bn_add_mod_n len inline_for_extraction noextract let bn_add_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_add_mod_n_st t len = match t with | U32 -> bn_add_mod_n_u32 len | U64 -> bn_add_mod_n_u64 len let bn_sub_mod_n_u32 (len:size_t{v len > 0}) : bn_sub_mod_n_st U32 len = bn_sub_mod_n len let bn_sub_mod_n_u64 (len:size_t{v len > 0}) : bn_sub_mod_n_st U64 len = bn_sub_mod_n len inline_for_extraction noextract let bn_sub_mod_n_ (#t:limb_t) (len:size_t{v len > 0}) : bn_sub_mod_n_st t len = match t with | U32 -> bn_sub_mod_n_u32 len | U64 -> bn_sub_mod_n_u64 len /// This is a default implementation that *will* generate code depending on /// `len` at run-time! Only use if you want to generate run-time generic /// functions! let mk_runtime_bn (t:limb_t) (len:meta_len t) : bn t = { len = len; add = Hacl.Bignum.Addition.bn_add_eq_len_u len; sub = Hacl.Bignum.Addition.bn_sub_eq_len_u len; add_mod_n = bn_add_mod_n_ len; sub_mod_n = bn_sub_mod_n_ len; mul = bn_karatsuba_mul len; sqr = bn_karatsuba_sqr len; } let mk_runtime_bn_len_lemma t len = () (* bignum comparison and test functions *) let bn_is_odd #t len a = Hacl.Bignum.Comparison.bn_is_odd len a let bn_eq_mask #t len a b = Hacl.Bignum.Comparison.bn_eq_mask len a b let bn_is_zero_mask #t len b = Hacl.Bignum.Comparison.bn_is_zero_mask len b let bn_lt_mask #t len a b = Hacl.Bignum.Comparison.bn_lt_mask len a b let bn_lt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_lt_pow2_mask len b x let bn_gt_pow2_mask #t len b x = Hacl.Bignum.Comparison.bn_gt_pow2_mask len b x (* Convertion functions *) let bn_from_uint #t len x b = Hacl.Bignum.Convert.bn_from_uint len x b let bn_from_bytes_be #t len b res = Hacl.Bignum.Convert.bn_from_bytes_be len b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Hacl.Spec.Bignum.fst.checked", "Hacl.Bignum.Multiplication.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Karatsuba.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Comparison.fst.checked", "Hacl.Bignum.Addition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.ST.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.numbytes t * Lib.IntTypes.v (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) <= Lib.IntTypes.max_size_t } -> b: Hacl.Bignum.Definitions.lbignum t (Hacl.Bignum.Definitions.blocks len (Lib.IntTypes.size (Lib.IntTypes.numbytes t))) -> res: Lib.Buffer.lbuffer Lib.IntTypes.uint8 len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Bignum.Convert.bn_to_bytes_be", "Prims.unit" ]
[]
false
true
false
false
false
let bn_to_bytes_be #t len b res =
Hacl.Bignum.Convert.bn_to_bytes_be len b res
false