effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_no_key_free =
false
null
false
F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.free", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "FStar.Ghost.hide", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_no_key_free : Hacl.Streaming.Functor.free_st (Hacl.Streaming.Blake2.blake2s_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2s_32_no_key_free
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.free_st (Hacl.Streaming.Blake2.blake2s_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 86, "end_line": 669, "start_col": 2, "start_line": 669 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_no_key_create_in =
false
null
false
F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.create_in", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_no_key_create_in : Hacl.Streaming.Functor.create_in_st (Hacl.Streaming.Blake2.blake2s_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2s_32_no_key_create_in
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.create_in_st (Hacl.Streaming.Blake2.blake2s_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 82, "end_line": 653, "start_col": 2, "start_line": 653 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish
let blake2s_32 kk =
false
null
false
blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.key_size", "Spec.Blake2.Blake2S", "Hacl.Streaming.Blake2.blake2", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.blake2s_init", "Hacl.Blake2s_32.blake2s_update_multi", "Hacl.Blake2s_32.blake2s_update_last", "Hacl.Blake2s_32.blake2s_finish", "Hacl.Streaming.Interface.block", "Prims.unit" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32 : kk: Hacl.Streaming.Blake2.key_size Spec.Blake2.Blake2S -> Hacl.Streaming.Interface.block Prims.unit
[]
Hacl.Streaming.Blake2.blake2s_32
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
kk: Hacl.Streaming.Blake2.key_size Spec.Blake2.Blake2S -> Hacl.Streaming.Interface.block Prims.unit
{ "end_col": 63, "end_line": 625, "start_col": 2, "start_line": 624 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_state =
false
null
false
F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.state_s", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_state : Type0
[]
Hacl.Streaming.Blake2.blake2s_32_state
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 101, "end_line": 639, "start_col": 23, "start_line": 639 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_no_key_finish =
false
null
false
F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.mk_finish", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_no_key_finish : Hacl.Streaming.Functor.finish_st (Hacl.Streaming.Blake2.blake2s_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2s_32_no_key_finish
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.finish_st (Hacl.Streaming.Blake2.blake2s_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 82, "end_line": 665, "start_col": 2, "start_line": 665 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish
let blake2b_32 kk =
false
null
false
blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.key_size", "Spec.Blake2.Blake2B", "Hacl.Streaming.Blake2.blake2", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2b_32.blake2b_init", "Hacl.Blake2b_32.blake2b_update_multi", "Hacl.Blake2b_32.blake2b_update_last", "Hacl.Blake2b_32.blake2b_finish", "Hacl.Streaming.Interface.block", "Prims.unit" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32 : kk: Hacl.Streaming.Blake2.key_size Spec.Blake2.Blake2B -> Hacl.Streaming.Interface.block Prims.unit
[]
Hacl.Streaming.Blake2.blake2b_32
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
kk: Hacl.Streaming.Blake2.key_size Spec.Blake2.Blake2B -> Hacl.Streaming.Interface.block Prims.unit
{ "end_col": 63, "end_line": 630, "start_col": 2, "start_line": 629 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_no_key_init =
false
null
false
F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.init", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "FStar.Ghost.hide", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_no_key_init : Hacl.Streaming.Functor.init_st (Hacl.Streaming.Blake2.blake2s_32 0) (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2s_32_no_key_init
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.init_st (Hacl.Streaming.Blake2.blake2s_32 0) (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 77, "end_line": 657, "start_col": 2, "start_line": 657 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_no_key_update =
false
null
false
F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.update", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "FStar.Ghost.hide", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_no_key_update : Hacl.Streaming.Functor.update_st (Hacl.Streaming.Blake2.blake2s_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2s_32_no_key_update
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.update_st (Hacl.Streaming.Blake2.blake2s_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 88, "end_line": 661, "start_col": 2, "start_line": 661 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let empty_key a = I.optional_key () I.Erased (stateful_key a 0)
let empty_key a =
false
null
false
I.optional_key () I.Erased (stateful_key a 0)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Interface.optional_key", "Prims.unit", "Hacl.Streaming.Interface.Erased", "Hacl.Streaming.Blake2.stateful_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val empty_key : a: Hacl.Streaming.Blake2.alg -> Type0
[]
Hacl.Streaming.Blake2.empty_key
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> Type0
{ "end_col": 63, "end_line": 633, "start_col": 18, "start_line": 633 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_no_key_init = F.init (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
let blake2b_32_no_key_init =
false
null
false
F.init (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.init", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "FStar.Ghost.hide", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key", "Spec.Blake2.Blake2S" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")] let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) inline_for_extraction noextract [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_alloca = F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_create_in = F.create_in (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re)-initialization function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_no_key_init : Hacl.Streaming.Functor.init_st (Hacl.Streaming.Blake2.blake2b_32 0) (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2b_32_no_key_init
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.init_st (Hacl.Streaming.Blake2.blake2b_32 0) (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 77, "end_line": 682, "start_col": 2, "start_line": 682 }
Prims.Tot
val init_s (a: alg) (kk: size_nat{kk <= max_key a}) : Tot (t a)
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a)
val init_s (a: alg) (kk: size_nat{kk <= max_key a}) : Tot (t a) let init_s (a: alg) (kk: size_nat{kk <= max_key a}) : Tot (t a) =
false
null
false
Spec.blake2_init_hash a kk (output_size a)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Streaming.Blake2.max_key", "Spec.Blake2.blake2_init_hash", "Hacl.Streaming.Blake2.output_size", "Hacl.Streaming.Blake2.t" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_s (a: alg) (kk: size_nat{kk <= max_key a}) : Tot (t a)
[]
Hacl.Streaming.Blake2.init_s
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.size_nat{kk <= Hacl.Streaming.Blake2.max_key a} -> Hacl.Streaming.Blake2.t a
{ "end_col": 44, "end_line": 267, "start_col": 2, "start_line": 267 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B)
let blake2b_32_state =
false
null
false
F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.state_s", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_state : Type0
[]
Hacl.Streaming.Blake2.blake2b_32_state
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 101, "end_line": 640, "start_col": 23, "start_line": 640 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_no_key_update = F.update (blake2b_32 0) (G.hide ()) (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
let blake2b_32_no_key_update =
false
null
false
F.update (blake2b_32 0) (G.hide ()) (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.update", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "FStar.Ghost.hide", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key", "Spec.Blake2.Blake2S" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")] let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) inline_for_extraction noextract [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_alloca = F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_create_in = F.create_in (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re)-initialization function when there is no key")] let blake2b_32_no_key_init = F.init (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_no_key_update : Hacl.Streaming.Functor.update_st (Hacl.Streaming.Blake2.blake2b_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2b_32_no_key_update
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.update_st (Hacl.Streaming.Blake2.blake2b_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 88, "end_line": 686, "start_col": 2, "start_line": 686 }
Prims.Tot
val stateful_key_to_buffer (#a: alg) (#kk: key_size a) (key: stateful_key_t a kk) : b: B.buffer uint8 {B.length b = kk}
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key
val stateful_key_to_buffer (#a: alg) (#kk: key_size a) (key: stateful_key_t a kk) : b: B.buffer uint8 {B.length b = kk} let stateful_key_to_buffer (#a: alg) (#kk: key_size a) (key: stateful_key_t a kk) : b: B.buffer uint8 {B.length b = kk} =
false
null
false
if kk = 0 then B.null #uint8 else key
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.key_size", "Hacl.Streaming.Blake2.stateful_key_t", "Prims.op_Equality", "Prims.int", "LowStar.Buffer.null", "Hacl.Streaming.Blake2.uint8", "Prims.bool", "LowStar.Buffer.buffer", "Prims.b2t", "Prims.nat", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stateful_key_to_buffer (#a: alg) (#kk: key_size a) (key: stateful_key_t a kk) : b: B.buffer uint8 {B.length b = kk}
[]
Hacl.Streaming.Blake2.stateful_key_to_buffer
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
key: Hacl.Streaming.Blake2.stateful_key_t a kk -> b: LowStar.Buffer.buffer Hacl.Streaming.Blake2.uint8 {LowStar.Monotonic.Buffer.length b = kk}
{ "end_col": 39, "end_line": 216, "start_col": 2, "start_line": 216 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_no_key_alloca = F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B)
let blake2b_32_no_key_alloca =
false
null
false
F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.alloca", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")] let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) inline_for_extraction noextract [@ (Comment " State allocation function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_no_key_alloca : Hacl.Streaming.Functor.alloca_st (Hacl.Streaming.Blake2.blake2b_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2B)
[]
Hacl.Streaming.Blake2.blake2b_32_no_key_alloca
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.alloca_st (Hacl.Streaming.Blake2.blake2b_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2B)
{ "end_col": 79, "end_line": 674, "start_col": 2, "start_line": 674 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let output_len (a : alg) = U32.uint_to_t (output_size a)
let output_len (a: alg) =
false
null
false
U32.uint_to_t (output_size a)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "FStar.UInt32.uint_to_t", "Hacl.Streaming.Blake2.output_size", "FStar.UInt32.t" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val output_len : a: Hacl.Streaming.Blake2.alg -> FStar.UInt32.t
[]
Hacl.Streaming.Blake2.output_len
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> FStar.UInt32.t
{ "end_col": 56, "end_line": 245, "start_col": 27, "start_line": 245 }
Prims.Tot
val finish_s (#a: alg) (acc: t a) : output: S.seq uint8 {S.length output = U32.v (output_len a)}
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a))
val finish_s (#a: alg) (acc: t a) : output: S.seq uint8 {S.length output = U32.v (output_len a)} let finish_s (#a: alg) (acc: t a) : output: S.seq uint8 {S.length output = U32.v (output_len a)} =
false
null
false
Spec.blake2_finish a acc (U32.v (output_len a))
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.t", "Spec.Blake2.blake2_finish", "FStar.UInt32.v", "Hacl.Streaming.Blake2.output_len", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Seq.Base.length" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finish_s (#a: alg) (acc: t a) : output: S.seq uint8 {S.length output = U32.v (output_len a)}
[]
Hacl.Streaming.Blake2.finish_s
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
acc: Hacl.Streaming.Blake2.t a -> output: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 {FStar.Seq.Base.length output = FStar.UInt32.v (Hacl.Streaming.Blake2.output_len a)}
{ "end_col": 49, "end_line": 290, "start_col": 2, "start_line": 290 }
Prims.Tot
val max_input_length (a: alg) : n: nat{n <= Spec.max_limb a /\ n > Spec.size_block a}
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1
val max_input_length (a: alg) : n: nat{n <= Spec.max_limb a /\ n > Spec.size_block a} let max_input_length (a: alg) : n: nat{n <= Spec.max_limb a /\ n > Spec.size_block a} =
false
null
false
assert_norm (pow2 64 < pow2 128); pow2 64 - 1
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Prims.op_Subtraction", "Prims.pow2", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Spec.Blake2.max_limb", "Prims.op_GreaterThan", "Spec.Blake2.size_block" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_input_length (a: alg) : n: nat{n <= Spec.max_limb a /\ n > Spec.size_block a}
[]
Hacl.Streaming.Blake2.max_input_length
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> n: Prims.nat{n <= Spec.Blake2.max_limb a /\ n > Spec.Blake2.size_block a}
{ "end_col": 13, "end_line": 230, "start_col": 2, "start_line": 229 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a)
let spec_s (a: alg) (kk: size_nat{kk <= max_key a}) (key: lbytes kk) (input: S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a }) =
false
null
false
Spec.blake2 a input kk key (output_size a)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Streaming.Blake2.max_key", "Hacl.Streaming.Blake2.lbytes", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Hacl.Streaming.Blake2.max_input_length", "Prims.bool", "Prims.op_Addition", "Spec.Blake2.size_block", "Spec.Blake2.blake2", "Hacl.Streaming.Blake2.output_size", "Lib.ByteSequence.lbytes" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk)
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val spec_s : a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.size_nat{kk <= Hacl.Streaming.Blake2.max_key a} -> key: Hacl.Streaming.Blake2.lbytes kk -> input: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 { (match kk = 0 with | true -> FStar.Seq.Base.length input <= Hacl.Streaming.Blake2.max_input_length a | _ -> FStar.Seq.Base.length input + Spec.Blake2.size_block a <= Hacl.Streaming.Blake2.max_input_length a) <: Type0 } -> Lib.ByteSequence.lbytes (Hacl.Streaming.Blake2.output_size a)
[]
Hacl.Streaming.Blake2.spec_s
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.size_nat{kk <= Hacl.Streaming.Blake2.max_key a} -> key: Hacl.Streaming.Blake2.lbytes kk -> input: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 { (match kk = 0 with | true -> FStar.Seq.Base.length input <= Hacl.Streaming.Blake2.max_input_length a | _ -> FStar.Seq.Base.length input + Spec.Blake2.size_block a <= Hacl.Streaming.Blake2.max_input_length a) <: Type0 } -> Lib.ByteSequence.lbytes (Hacl.Streaming.Blake2.output_size a)
{ "end_col": 44, "end_line": 297, "start_col": 2, "start_line": 297 }
Prims.Tot
val state_to_lbuffer (#a: alg) (#m: m_spec) (s: Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m))
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s
val state_to_lbuffer (#a: alg) (#m: m_spec) (s: Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) let state_to_lbuffer (#a: alg) (#m: m_spec) (s: Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) =
false
null
false
s
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.m_spec", "Hacl.Impl.Blake2.Core.state_p", "LowStar.Buffer.lbuffer", "Hacl.Impl.Blake2.Core.element_t", "FStar.Mul.op_Star", "FStar.UInt32.v", "Hacl.Impl.Blake2.Core.row_len" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_to_lbuffer (#a: alg) (#m: m_spec) (s: Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m))
[]
Hacl.Streaming.Blake2.state_to_lbuffer
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Hacl.Impl.Blake2.Core.state_p a m -> LowStar.Buffer.lbuffer (Hacl.Impl.Blake2.Core.element_t a m) (4 * FStar.UInt32.v (Hacl.Impl.Blake2.Core.row_len a m))
{ "end_col": 3, "end_line": 90, "start_col": 2, "start_line": 90 }
Prims.Tot
val stateful_key (a: alg) (kk: key_size a) : I.stateful unit
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ())
val stateful_key (a: alg) (kk: key_size a) : I.stateful unit let stateful_key (a: alg) (kk: key_size a) : I.stateful unit =
false
null
false
I.Stateful (fun _ -> stateful_key_t a kk) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s: S.seq uint8 {S.length s == kk}) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (fun #_ l s h0 h1 -> ()) (fun #_ l s h0 h1 -> ()) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8)) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk))
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.key_size", "Hacl.Streaming.Interface.Stateful", "Prims.unit", "Hacl.Streaming.Blake2.stateful_key_t", "FStar.Monotonic.HyperStack.mem", "Prims.op_Equality", "Prims.int", "LowStar.Monotonic.Buffer.loc_none", "Prims.bool", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "Hacl.Streaming.Blake2.uint8", "LowStar.Buffer.trivial_preorder", "LowStar.Buffer.buffer", "LowStar.Monotonic.Buffer.loc", "Prims.l_True", "LowStar.Monotonic.Buffer.freeable", "LowStar.Monotonic.Buffer.live", "FStar.Seq.Base.seq", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "LowStar.Monotonic.Buffer.as_seq", "Prims.op_GreaterThan", "Hacl.Streaming.Blake2.buffer_to_stateful_key_t", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.alloca", "Lib.IntTypes.u8", "FStar.UInt32.uint_to_t", "LowStar.Monotonic.Buffer.mbuffer", "Prims.l_and", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "Hacl.Streaming.Blake2.unit_to_stateful_key_t", "FStar.Monotonic.HyperHeap.rid", "LowStar.Buffer.malloc", "LowStar.Monotonic.Buffer.frameOf", "FStar.Ghost.erased", "LowStar.Monotonic.Buffer.free", "LowStar.Monotonic.Buffer.blit", "FStar.UInt32.__uint_to_t", "Hacl.Streaming.Interface.stateful" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stateful_key (a: alg) (kk: key_size a) : I.stateful unit
[]
Hacl.Streaming.Blake2.stateful_key
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.key_size a -> Hacl.Streaming.Interface.stateful Prims.unit
{ "end_col": 14, "end_line": 210, "start_col": 2, "start_line": 174 }
Prims.Tot
val stateful_blake2 (a: alg) (m: m_spec) : I.stateful unit
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m))
val stateful_blake2 (a: alg) (m: m_spec) : I.stateful unit let stateful_blake2 (a: alg) (m: m_spec) : I.stateful unit =
false
null
false
I.Stateful (fun () -> s a m) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (fun () h acc -> s_v h acc) (fun #_ h acc -> let wv, b = acc in ()) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (fun #_ _ _ _ _ -> ()) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (fun _ acc -> match acc with | wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (fun _ src dst -> match src with | src_wv, src_b -> match dst with | src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m))
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.m_spec", "Hacl.Streaming.Interface.Stateful", "Prims.unit", "Hacl.Streaming.Blake2.s", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Blake2.Core.state_p", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "Hacl.Impl.Blake2.Core.element_t", "LowStar.Buffer.trivial_preorder", "Hacl.Streaming.Blake2.state_to_lbuffer", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.freeable", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.disjoint", "Hacl.Streaming.Blake2.t", "Hacl.Streaming.Blake2.s_v", "FStar.Pervasives.Native.Mktuple2", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.mul_mod", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Hacl.Impl.Blake2.Core.row_len", "Hacl.Impl.Blake2.Core.alloc_state", "FStar.Monotonic.HyperHeap.rid", "LowStar.Monotonic.Buffer.mbuffer", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.mul", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Buffer.malloc", "Hacl.Impl.Blake2.Core.zero_element", "FStar.UInt32.op_Star_Hat", "FStar.UInt32.__uint_to_t", "FStar.Ghost.erased", "LowStar.Monotonic.Buffer.free", "LowStar.Monotonic.Buffer.blit", "Hacl.Streaming.Interface.stateful" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val stateful_blake2 (a: alg) (m: m_spec) : I.stateful unit
[]
Hacl.Streaming.Blake2.stateful_blake2
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> m: Hacl.Streaming.Blake2.m_spec -> Hacl.Streaming.Interface.stateful Prims.unit
{ "end_col": 43, "end_line": 138, "start_col": 2, "start_line": 94 }
FStar.Pervasives.Lemma
val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc))
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc
val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen =
false
null
false
Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "lemma" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.t", "Prims.nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Spec.Blake2.size_block", "Lib.LoopCombinators.eq_repeati0", "Spec.Blake2.state", "Prims.op_Division", "FStar.UInt32.v", "Hacl.Streaming.Blake2.block_len", "Spec.Blake2.blake2_update1", "FStar.Seq.Base.empty", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.unit" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc))
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc))
[]
Hacl.Streaming.Blake2.update_multi_zero
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
acc: Hacl.Streaming.Blake2.t a -> prevlen: Prims.nat{prevlen % Spec.Blake2.size_block a = 0} -> FStar.Pervasives.Lemma (requires prevlen <= Hacl.Streaming.Blake2.max_input_length a) (ensures Hacl.Streaming.Blake2.update_multi_s acc prevlen FStar.Seq.Base.empty == acc)
{ "end_col": 103, "end_line": 311, "start_col": 2, "start_line": 311 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
let blake2s_32_no_key_alloca =
false
null
false
F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.alloca", "Prims.unit", "Hacl.Streaming.Blake2.blake2s_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_32_no_key_alloca : Hacl.Streaming.Functor.alloca_st (Hacl.Streaming.Blake2.blake2s_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2s_32_no_key_alloca
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.alloca_st (Hacl.Streaming.Blake2.blake2s_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2S Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 79, "end_line": 649, "start_col": 2, "start_line": 649 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_no_key_create_in = F.create_in (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
let blake2b_32_no_key_create_in =
false
null
false
F.create_in (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.create_in", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key", "Spec.Blake2.Blake2S" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")] let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) inline_for_extraction noextract [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_alloca = F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) [@ (Comment " State allocation function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_no_key_create_in : Hacl.Streaming.Functor.create_in_st (Hacl.Streaming.Blake2.blake2b_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2b_32_no_key_create_in
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.create_in_st (Hacl.Streaming.Blake2.blake2b_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 82, "end_line": 678, "start_col": 2, "start_line": 678 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_no_key_finish = F.mk_finish (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
let blake2b_32_no_key_finish =
false
null
false
F.mk_finish (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.mk_finish", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key", "Spec.Blake2.Blake2S" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")] let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) inline_for_extraction noextract [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_alloca = F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_create_in = F.create_in (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re)-initialization function when there is no key")] let blake2b_32_no_key_init = F.init (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2b_32_no_key_update = F.update (blake2b_32 0) (G.hide ()) (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_no_key_finish : Hacl.Streaming.Functor.finish_st (Hacl.Streaming.Blake2.blake2b_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2b_32_no_key_finish
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.finish_st (Hacl.Streaming.Blake2.blake2b_32 0) () (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 82, "end_line": 690, "start_col": 2, "start_line": 690 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2b_32_no_key_free = F.free (blake2b_32 0) (G.hide ()) (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
let blake2b_32_no_key_free =
false
null
false
F.free (blake2b_32 0) (G.hide ()) (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Functor.free", "Prims.unit", "Hacl.Streaming.Blake2.blake2b_32", "FStar.Ghost.hide", "Hacl.Streaming.Blake2.s", "Spec.Blake2.Blake2B", "Hacl.Impl.Blake2.Core.M32", "Hacl.Streaming.Blake2.empty_key", "Spec.Blake2.Blake2S" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h) #pop-options /// Introducing intermediate definitions for the instantiation inline_for_extraction noextract let blake2s_32 kk = blake2 Spec.Blake2S Core.M32 kk Blake2s32.blake2s_init Blake2s32.blake2s_update_multi Blake2s32.blake2s_update_last Blake2s32.blake2s_finish inline_for_extraction noextract let blake2b_32 kk = blake2 Spec.Blake2B Core.M32 kk Blake2b32.blake2b_init Blake2b32.blake2b_update_multi Blake2b32.blake2b_update_last Blake2b32.blake2b_finish inline_for_extraction noextract let empty_key a = I.optional_key () I.Erased (stateful_key a 0) /// Type abbreviations - makes KaRaMeL use pretty names in the generated code let blake2s_32_block_state = s Spec.Blake2S Core.M32 let blake2b_32_block_state = s Spec.Blake2B Core.M32 let blake2s_32_state = F.state_s (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) let blake2b_32_state = F.state_s (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) /// The incremental hash functions instantiations. Note that we can't write a /// generic one, because the normalization then performed by KaRaMeL explodes. /// All those implementations are for non-keyed hash. inline_for_extraction noextract let blake2s_32_no_key_alloca = F.alloca (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " State allocation function when there is no key")] let blake2s_32_no_key_create_in = F.create_in (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re-)initialization function when there is no key")] let blake2s_32_no_key_init = F.init (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2s_32_no_key_update = F.update (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2s_32_no_key_finish = F.mk_finish (blake2s_32 0) () (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")] let blake2s_32_no_key_free = F.free (blake2s_32 0) (G.hide ()) (s Spec.Blake2S Core.M32) (empty_key Spec.Blake2S) inline_for_extraction noextract [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_alloca = F.alloca (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2B) [@ (Comment " State allocation function when there is no key")] let blake2b_32_no_key_create_in = F.create_in (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " (Re)-initialization function when there is no key")] let blake2b_32_no_key_init = F.init (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Update function when there is no key; 0 = success, 1 = max length exceeded")] let blake2b_32_no_key_update = F.update (blake2b_32 0) (G.hide ()) (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Finish function when there is no key")] let blake2b_32_no_key_finish = F.mk_finish (blake2b_32 0) () (s Spec.Blake2B Core.M32) (empty_key Spec.Blake2S) [@ (Comment " Free state function when there is no key")]
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_32_no_key_free : Hacl.Streaming.Functor.free_st (Hacl.Streaming.Blake2.blake2b_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
[]
Hacl.Streaming.Blake2.blake2b_32_no_key_free
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Streaming.Functor.free_st (Hacl.Streaming.Blake2.blake2b_32 0) (FStar.Ghost.reveal (FStar.Ghost.hide ())) (Hacl.Streaming.Blake2.s Spec.Blake2.Blake2B Hacl.Impl.Blake2.Core.M32) (Hacl.Streaming.Blake2.empty_key Spec.Blake2.Blake2S)
{ "end_col": 86, "end_line": 694, "start_col": 2, "start_line": 694 }
Prims.Tot
val update_multi_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 { prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a)
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc
val update_multi_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 { prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) let update_multi_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 { prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) =
false
null
false
let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.t", "Prims.nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Spec.Blake2.size_block", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.Seq.Base.length", "Hacl.Streaming.Blake2.max_input_length", "Lib.LoopCombinators.repeati", "Spec.Blake2.state", "Spec.Blake2.blake2_update1", "Prims.op_Division", "FStar.UInt32.v", "Hacl.Streaming.Blake2.block_len" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_multi_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 { prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a)
[]
Hacl.Streaming.Blake2.update_multi_s
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
acc: Hacl.Streaming.Blake2.t a -> prevlen: Prims.nat{prevlen % Spec.Blake2.size_block a = 0} -> input: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 { prevlen + FStar.Seq.Base.length input <= Hacl.Streaming.Blake2.max_input_length a /\ FStar.Seq.Base.length input % Spec.Blake2.size_block a = 0 } -> Hacl.Streaming.Blake2.t a
{ "end_col": 74, "end_line": 277, "start_col": 1, "start_line": 275 }
Prims.Tot
val max_input_len (a: alg) : (x: U64.t{U64.v x == max_input_length a})
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL
val max_input_len (a: alg) : (x: U64.t{U64.v x == max_input_length a}) let max_input_len (a: alg) : (x: U64.t{U64.v x == max_input_length a}) =
false
null
false
0xffffffffffffffffuL
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "FStar.UInt64.__uint_to_t", "FStar.UInt64.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThanOrEqual", "Spec.Blake2.max_limb", "Prims.op_GreaterThan", "Spec.Blake2.size_block", "FStar.UInt64.v", "Hacl.Streaming.Blake2.max_input_length" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_input_len (a: alg) : (x: U64.t{U64.v x == max_input_length a})
[]
Hacl.Streaming.Blake2.max_input_len
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> x: FStar.UInt64.t{FStar.UInt64.v x == Hacl.Streaming.Blake2.max_input_length a}
{ "end_col": 94, "end_line": 233, "start_col": 74, "start_line": 233 }
Prims.Tot
val blake2_prevlen (a: alg) (prevlen: U64.t{U64.v prevlen <= max_input_length a}) : x: Spec.limb_t a {Lib.IntTypes.uint_v x = U64.v prevlen}
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x
val blake2_prevlen (a: alg) (prevlen: U64.t{U64.v prevlen <= max_input_length a}) : x: Spec.limb_t a {Lib.IntTypes.uint_v x = U64.v prevlen} let blake2_prevlen (a: alg) (prevlen: U64.t{U64.v prevlen <= max_input_length a}) : x: Spec.limb_t a {Lib.IntTypes.uint_v x = U64.v prevlen} =
false
null
false
let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@@ inline_let ]let x:uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "FStar.UInt64.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt64.v", "Hacl.Streaming.Blake2.max_input_length", "Lib.IntTypes.to_u64", "Lib.IntTypes.U64", "Lib.IntTypes.PUB", "Lib.IntTypes.cast", "Lib.IntTypes.SEC", "Lib.IntTypes.U128", "Lib.IntTypes.int_t", "Spec.Blake2.limb_t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Spec.Blake2.limb_inttype", "FStar.UInt.size", "FStar.UInt64.n", "Lib.IntTypes.uint_v" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a {
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2_prevlen (a: alg) (prevlen: U64.t{U64.v prevlen <= max_input_length a}) : x: Spec.limb_t a {Lib.IntTypes.uint_v x = U64.v prevlen}
[]
Hacl.Streaming.Blake2.blake2_prevlen
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> prevlen: FStar.UInt64.t{FStar.UInt64.v prevlen <= Hacl.Streaming.Blake2.max_input_length a} -> x: Spec.Blake2.limb_t a {Lib.IntTypes.uint_v x = FStar.UInt64.v prevlen}
{ "end_col": 32, "end_line": 259, "start_col": 2, "start_line": 254 }
Prims.Tot
val update_last_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 {S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a}) : Tot (t a)
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc
val update_last_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 {S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a}) : Tot (t a) let update_last_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 {S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a}) : Tot (t a) =
false
null
false
Spec.blake2_update_last a prevlen (S.length input) input acc
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.t", "Prims.nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Spec.Blake2.size_block", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.Seq.Base.length", "Hacl.Streaming.Blake2.max_input_length", "Spec.Blake2.blake2_update_last" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) :
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_last_s (#a: alg) (acc: t a) (prevlen: nat{prevlen % Spec.size_block a = 0}) (input: Seq.seq uint8 {S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a}) : Tot (t a)
[]
Hacl.Streaming.Blake2.update_last_s
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
acc: Hacl.Streaming.Blake2.t a -> prevlen: Prims.nat{prevlen % Spec.Blake2.size_block a = 0} -> input: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 { FStar.Seq.Base.length input + prevlen <= Hacl.Streaming.Blake2.max_input_length a /\ FStar.Seq.Base.length input <= Spec.Blake2.size_block a } -> Hacl.Streaming.Blake2.t a
{ "end_col": 62, "end_line": 285, "start_col": 2, "start_line": 285 }
FStar.HyperStack.ST.Stack
val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end)
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end
val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ =
false
null
false
if kk = 0 then () else let h0 = ST.get () in [@@ inline_let ]let sub_b_len = let open U32 in block_len a -^ U32.uint_to_t kk in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; let h1 = ST.get () in assert ((S.slice (B.as_seq h1 buf_) kk (Spec.size_block a)) `S.equal` (B.as_seq h1 sub_b)); Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); let h2 = ST.get () in let k:LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in let buf_v1:LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in let buf_v2:LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in assert (buf_v2 `S.equal` (LS.update_sub buf_v1 0 kk k)); let zeroed:LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in assert ((B.as_seq h1 sub_b) `S.equal` zeroed); let key_and_zeroed:LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in assert (S.equal (S.slice key_and_zeroed 0 kk) k); assert (S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; assert (buf_v2 `S.equal` key_and_zeroed); let input = Spec.blake2_key_block a kk k in let key_block0:LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in assert (input `S.equal` (LS.update_sub key_block0 0 kk k)); assert (Seq.equal (LS.sub key_and_zeroed 0 kk) k); assert (Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; assert (input `S.equal` key_and_zeroed)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.key_size", "Hacl.Streaming.Blake2.stateful_key_t", "LowStar.Buffer.buffer", "Hacl.Streaming.Blake2.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Blake2.size_block", "Prims.int", "Prims.unit", "Prims.bool", "Prims._assert", "FStar.Seq.Base.equal", "Lib.IntTypes.uint8", "Lib.Sequence.lemma_update_sub", "Lib.Sequence.sub", "Prims.op_Subtraction", "Lib.Sequence.update_sub", "Lib.Sequence.lseq", "FStar.Seq.Base.create", "Lib.IntTypes.u8", "Spec.Blake2.block_s", "Spec.Blake2.blake2_key_block", "FStar.Seq.Base.slice", "FStar.Seq.Base.append", "LowStar.Monotonic.Buffer.as_seq", "Hacl.Streaming.Interface.__proj__Stateful__item__v", "Hacl.Streaming.Blake2.stateful_key", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.update_sub", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.__uint_to_t", "Hacl.Streaming.Blake2.stateful_key_to_buffer", "LowStar.Monotonic.Buffer.fill", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.sub", "FStar.Ghost.hide", "FStar.UInt32.t", "FStar.UInt32.op_Subtraction_Hat", "Hacl.Streaming.Blake2.block_len" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end)
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end)
[]
Hacl.Streaming.Blake2.init_key_block
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.key_size a -> k: Hacl.Streaming.Blake2.stateful_key_t a kk -> buf_: LowStar.Buffer.buffer Hacl.Streaming.Blake2.uint8 {LowStar.Monotonic.Buffer.length buf_ = Spec.Blake2.size_block a} -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 7, "end_line": 548, "start_col": 2, "start_line": 507 }
Prims.Tot
val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a }
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4
val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } let blake2_hash_incremental_s a kk k input0 =
false
null
false
let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Streaming.Blake2.max_key", "Hacl.Streaming.Blake2.lbytes", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Hacl.Streaming.Blake2.max_input_length", "Prims.bool", "Prims.op_Addition", "Spec.Blake2.size_block", "Lib.UpdateMulti.uint8", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.v", "Hacl.Streaming.Blake2.output_len", "Hacl.Streaming.Blake2.finish_s", "Hacl.Streaming.Blake2.t", "Hacl.Streaming.Blake2.update_last_s", "Hacl.Streaming.Blake2.update_multi_s", "Hacl.Streaming.Blake2.init_s", "Prims.nat", "Hacl.Streaming.Blake2.output_size", "FStar.Pervasives.Native.tuple2", "Lib.UpdateMulti.split_at_last_lazy", "Hacl.Streaming.Blake2.block_len", "Prims.unit", "FStar.Math.Lemmas.modulo_lemma", "Prims._assert", "FStar.Seq.Base.append", "Prims.op_GreaterThan", "Spec.Blake2.blake2_key_block", "FStar.Seq.Base.empty" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a }
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a }
[]
Hacl.Streaming.Blake2.blake2_hash_incremental_s
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.size_nat{kk <= Hacl.Streaming.Blake2.max_key a} -> k: Hacl.Streaming.Blake2.lbytes kk -> input: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 { (match kk = 0 with | true -> FStar.Seq.Base.length input <= Hacl.Streaming.Blake2.max_input_length a | _ -> FStar.Seq.Base.length input + Spec.Blake2.size_block a <= Hacl.Streaming.Blake2.max_input_length a) <: Type0 } -> output: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 {FStar.Seq.Base.length output = Hacl.Streaming.Blake2.output_size a}
{ "end_col": 6, "end_line": 402, "start_col": 45, "start_line": 391 }
FStar.Pervasives.Lemma
val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input))
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; }
val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 =
false
null
false
let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i: nat{i < nb1}) (acc: t a) : Lemma (f i acc == f1 i acc) = assert ((Spec.get_blocki a input i) `Seq.equal` (Spec.get_blocki a input1 i)) in let aux2 (i: nat{i < nb2}) (acc: t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert ((Spec.get_blocki a input2 i) `Seq.equal` (Spec.get_blocki a input (i + nb1))) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc ( == ) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; ( == ) { () } repeati nb2 f2 (repeati nb1 f1 acc); ( == ) { (Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc) } repeati nb2 f2 (repeati nb1 f acc); ( == ) { (repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc)) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); ( == ) { (Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc)) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); ( == ) { (repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc) } repeati nb f acc; ( == ) { () } update_multi_s acc prevlen1 input; }
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "lemma" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.t", "Prims.nat", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "FStar.Calc.calc_finish", "Prims.eq2", "Hacl.Streaming.Blake2.update_multi_s", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeati", "Spec.Blake2.state", "Lib.LoopCombinators.repeat_right", "Prims.op_Addition", "Lib.LoopCombinators.fixed_a", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Lib.Sequence.Lemmas.repeati_extensionality", "FStar.Classical.forall_intro_2", "Prims.b2t", "Prims.op_LessThan", "Lib.LoopCombinators.repeati_def", "Lib.Sequence.Lemmas.repeat_gen_right_extensionality", "Lib.LoopCombinators.repeat_right_plus", "Prims.l_True", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.Blake2.wt", "Lib.IntTypes.SEC", "FStar.Pervasives.pattern", "Prims._assert", "FStar.Seq.Base.equal", "Lib.IntTypes.uint8", "Spec.Blake2.get_blocki", "Prims.l_and", "Prims.op_Division", "Lib.Sequence.length", "Lib.IntTypes.U8", "Spec.Blake2.size_block", "Prims.op_LessThanOrEqual", "Spec.Blake2.max_limb", "Spec.Blake2.blake2_update1", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt32.v", "Hacl.Streaming.Blake2.block_len", "FStar.Seq.Base.append" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 400, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input))
[]
Hacl.Streaming.Blake2.update_multi_associative
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
acc: Hacl.Streaming.Blake2.t a -> prevlen1: Prims.nat -> prevlen2: Prims.nat -> input1: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 -> input2: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 -> FStar.Pervasives.Lemma (requires (FStar.Math.Lemmas.pos_times_pos_is_pos Spec.Blake2.size_block_w (Spec.Blake2.size_word a); prevlen1 % Spec.Blake2.size_block a = 0 /\ FStar.Seq.Base.length input1 % Spec.Blake2.size_block a = 0 /\ FStar.Seq.Base.length input2 % Spec.Blake2.size_block a = 0 /\ prevlen1 + FStar.Seq.Base.length input1 + FStar.Seq.Base.length input2 <= Hacl.Streaming.Blake2.max_input_length a /\ prevlen2 = prevlen1 + FStar.Seq.Base.length input1)) (ensures (let input = FStar.Seq.Base.append input1 input2 in FStar.Seq.Base.length input % Spec.Blake2.size_block a = 0 /\ prevlen2 % Spec.Blake2.size_block a = 0 /\ Hacl.Streaming.Blake2.update_multi_s (Hacl.Streaming.Blake2.update_multi_s acc prevlen1 input1) prevlen2 input2 == Hacl.Streaming.Blake2.update_multi_s acc prevlen1 input))
{ "end_col": 3, "end_line": 377, "start_col": 69, "start_line": 338 }
Prims.Tot
val blake2 (a: alg) (m: valid_m_spec a) (kk: key_size a) (init: blake2_init_st a m) (update_multi: blake2_update_multi_st a m) (update_last: blake2_update_last_st a m) (finish: blake2_finish_st a m) : I.block unit
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) : I.block unit = I.Block I.Erased (* key management *) (stateful_blake2 a m) (* state *) (stateful_key a kk) (* key *) unit (* output_length_t *) (fun () -> max_input_len a) (* max_input_length *) (fun () () -> output_size a) (* output_len *) (fun () -> block_len a) (* block_len *) (fun () -> block_len a) (* blocks_state_len *) (fun () -> if kk > 0 then block_len a else 0ul) (* init_input_len *) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (* init_s *) (fun () acc prevlen input -> update_multi_s acc prevlen input) (* update_multi_s *) (fun () acc prevlen input -> update_last_s acc prevlen input) (* update_last_s *) (fun () _k acc _ -> finish_s #a acc) (* finish_s *) (fun () k input l -> spec_s a kk k input) (* spec_s *) (* update_multi_zero *) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (* update_multi_associative *) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (* spec_is_incremental *) (fun _ acc -> ()) (* index_of_state *) (* init *) (fun _ key buf_ acc -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (* update_multi *) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` Core.size_block a in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (* update_last *) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (* finish *) (fun _ k acc dst _ -> [@inline_let] let wv = get_wv acc in [@inline_let] let h = get_state_p acc in finish (output_len a) dst h)
val blake2 (a: alg) (m: valid_m_spec a) (kk: key_size a) (init: blake2_init_st a m) (update_multi: blake2_update_multi_st a m) (update_last: blake2_update_last_st a m) (finish: blake2_finish_st a m) : I.block unit let blake2 (a: alg) (m: valid_m_spec a) (kk: key_size a) (init: blake2_init_st a m) (update_multi: blake2_update_multi_st a m) (update_last: blake2_update_last_st a m) (finish: blake2_finish_st a m) : I.block unit =
false
null
false
I.Block I.Erased (stateful_blake2 a m) (stateful_key a kk) unit (fun () -> max_input_len a) (fun () () -> output_size a) (fun () -> block_len a) (fun () -> block_len a) (fun () -> if kk > 0 then block_len a else 0ul) (fun () k -> if kk > 0 then Spec.blake2_key_block a kk k else S.empty) (fun () _k -> init_s a kk) (fun () acc prevlen input -> update_multi_s acc prevlen input) (fun () acc prevlen input -> update_last_s acc prevlen input) (fun () _k acc _ -> finish_s #a acc) (fun () k input l -> spec_s a kk k input) (fun () acc prevlen -> update_multi_zero #a acc prevlen) (fun () acc prevlen1 prevlen2 input1 input2 -> update_multi_associative acc prevlen1 prevlen2 input1 input2) (fun () k input _ -> spec_is_incremental a kk k input) (fun _ acc -> ()) (fun _ key buf_ acc -> [@@ inline_let ]let wv = get_wv acc in [@@ inline_let ]let h = get_state_p acc in init_key_block a kk key buf_; init h (Lib.IntTypes.size kk) (output_len a)) (fun _ acc prevlen blocks len -> let wv, hash = acc in let nb = len `U32.div` (Core.size_block a) in update_multi #len wv hash (blake2_prevlen a prevlen) blocks nb) (fun _ acc prevlen last last_len -> let wv, hash = acc in update_last #last_len wv hash (blake2_prevlen a prevlen) last_len last) (fun _ k acc dst _ -> [@@ inline_let ]let wv = get_wv acc in [@@ inline_let ]let h = get_state_p acc in finish (output_len a) dst h)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "total" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Impl.Blake2.Generic.valid_m_spec", "Hacl.Streaming.Blake2.key_size", "Hacl.Impl.Blake2.Generic.blake2_init_st", "Hacl.Impl.Blake2.Generic.blake2_update_multi_st", "Hacl.Impl.Blake2.Generic.blake2_update_last_st", "Hacl.Impl.Blake2.Generic.blake2_finish_st", "Hacl.Streaming.Interface.Block", "Prims.unit", "Hacl.Streaming.Interface.Erased", "Hacl.Streaming.Blake2.stateful_blake2", "Hacl.Streaming.Blake2.stateful_key", "Hacl.Streaming.Blake2.max_input_len", "FStar.UInt64.t", "Prims.b2t", "FStar.Integers.op_Greater", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt64.v", "Hacl.Streaming.Blake2.output_size", "Lib.IntTypes.size_nat", "Hacl.Streaming.Blake2.block_len", "FStar.UInt32.t", "FStar.UInt32.v", "Prims.l_and", "FStar.Integers.op_Greater_Equals", "Prims.op_Equality", "Prims.int", "FStar.Integers.op_Percent", "Prims.op_GreaterThan", "Prims.bool", "FStar.UInt32.__uint_to_t", "FStar.Integers.op_Less_Equals", "Hacl.Streaming.Interface.__proj__Stateful__item__t", "Spec.Blake2.blake2_key_block", "FStar.Seq.Base.empty", "Hacl.Streaming.Interface.uint8", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Seq.Base.length", "Hacl.Streaming.Blake2.init_s", "FStar.Integers.nat", "FStar.Integers.op_Plus", "Hacl.Streaming.Blake2.update_multi_s", "Hacl.Streaming.Blake2.update_last_s", "Hacl.Streaming.Blake2.finish_s", "Prims.nat", "Hacl.Streaming.Blake2.spec_s", "Prims.eq2", "Hacl.Streaming.Blake2.update_multi_zero", "Hacl.Streaming.Blake2.update_multi_associative", "Hacl.Streaming.Blake2.spec_is_incremental", "FStar.Ghost.erased", "Hacl.Streaming.Interface.__proj__Stateful__item__s", "FStar.Ghost.reveal", "LowStar.Buffer.buffer", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Lib.IntTypes.size", "Hacl.Streaming.Blake2.output_len", "Hacl.Streaming.Blake2.init_key_block", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Hacl.Impl.Blake2.Core.element_t", "Lib.IntTypes.mul_mod", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.uint_to_t", "Hacl.Impl.Blake2.Core.row_len", "Hacl.Streaming.Blake2.get_state_p", "Hacl.Streaming.Blake2.get_wv", "Hacl.Impl.Blake2.Core.state_p", "Hacl.Streaming.Blake2.blake2_prevlen", "FStar.UInt32.div", "Hacl.Impl.Blake2.Core.size_block", "LowStar.Monotonic.Buffer.len", "Hacl.Streaming.Interface.optional_key", "Hacl.Streaming.Interface.block" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver #push-options "--z3cliopt smt.arith.nl=false" let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a) #pop-options inline_for_extraction noextract val init_key_block (a : alg) (kk : key_size a) (k : stateful_key_t a kk) (buf_: B.buffer uint8 { B.length buf_ = Spec.size_block a }) : ST.Stack unit (requires fun h0 -> let key = stateful_key a kk in key.invariant h0 k /\ B.live h0 buf_ /\ B.(loc_disjoint (loc_buffer buf_) (key.footprint h0 k))) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer buf_) h0 h1) /\ begin let k = (stateful_key a kk).v () h0 k in let input_length = if kk > 0 then Spec.size_block a else 0 in let input = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in S.equal (S.slice (B.as_seq h1 buf_) 0 input_length) input end) let init_key_block a kk k buf_ = if kk = 0 then () else begin (**) let h0 = ST.get () in (* Set the end of the buffer to 0 *) [@inline_let] let sub_b_len = U32.(block_len a -^ U32.uint_to_t kk) in let sub_b = B.sub buf_ (U32.uint_to_t kk) sub_b_len in B.fill sub_b (Lib.IntTypes.u8 0) sub_b_len; (**) let h1 = ST.get () in (**) assert(S.slice (B.as_seq h1 buf_) kk (Spec.size_block a) `S.equal` B.as_seq h1 sub_b); (* Copy the key at the beginning of the buffer *) Lib.Buffer.update_sub #Lib.Buffer.MUT #uint8 #(U32.uint_to_t (Spec.size_block a)) buf_ 0ul (U32.uint_to_t kk) (stateful_key_to_buffer k); (**) let h2 = ST.get () in (**) begin (**) let k : LS.lseq uint8 kk = (stateful_key a kk).v () h0 k in (**) let buf_v1 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h1 buf_ in (**) let buf_v2 : LS.lseq uint8 (Spec.size_block a) = B.as_seq h2 buf_ in (* Prove that [buf_] is equal to [key @ create ... 0] *) (**) assert(buf_v2 `S.equal` LS.update_sub buf_v1 0 kk k); (**) let zeroed : LS.lseq uint8 (Spec.size_block a - kk) = S.create (Spec.size_block a - kk) (Lib.IntTypes.u8 0) in (**) assert(B.as_seq h1 sub_b `S.equal` zeroed); (**) let key_and_zeroed : LS.lseq uint8 (Spec.size_block a) = Seq.append k zeroed in (**) assert(S.equal (S.slice key_and_zeroed 0 kk) k); (**) assert(S.equal (S.slice key_and_zeroed kk (Spec.size_block a)) zeroed); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) buf_v1 0 kk k key_and_zeroed; (**) assert(buf_v2 `S.equal` key_and_zeroed); (* Prove that the initial input is equal to [key @ create ... 0] *) (**) let input = Spec.blake2_key_block a kk k in (**) let key_block0: LS.lseq uint8 (Spec.size_block a) = S.create (Spec.size_block a) (Lib.IntTypes.u8 0) in (**) assert(input `S.equal` LS.update_sub key_block0 0 kk k); (**) assert(Seq.equal (LS.sub key_and_zeroed 0 kk) k); (**) assert(Seq.equal (LS.sub key_and_zeroed kk (Spec.size_block a - kk)) (LS.sub key_block0 kk (Spec.size_block a - kk))); (**) LS.lemma_update_sub #uint8 #(Spec.size_block a) key_block0 0 kk k key_and_zeroed; (**) assert(input `S.equal` key_and_zeroed) (**) end end /// Runtime /// ------- #push-options "--ifuel 1"// --z3cliopt smt.arith.nl=false" inline_for_extraction noextract let blake2 (a : alg) (m : valid_m_spec a) (kk : key_size a) (init : blake2_init_st a m) (update_multi : blake2_update_multi_st a m) (update_last : blake2_update_last_st a m) (finish : blake2_finish_st a m) :
false
false
Hacl.Streaming.Blake2.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "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" }
null
val blake2 (a: alg) (m: valid_m_spec a) (kk: key_size a) (init: blake2_init_st a m) (update_multi: blake2_update_multi_st a m) (update_last: blake2_update_last_st a m) (finish: blake2_finish_st a m) : I.block unit
[]
Hacl.Streaming.Blake2.blake2
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> m: Hacl.Impl.Blake2.Generic.valid_m_spec a -> kk: Hacl.Streaming.Blake2.key_size a -> init: Hacl.Impl.Blake2.Generic.blake2_init_st a m -> update_multi: Hacl.Impl.Blake2.Generic.blake2_update_multi_st a m -> update_last: Hacl.Impl.Blake2.Generic.blake2_update_last_st a m -> finish: Hacl.Impl.Blake2.Generic.blake2_finish_st a m -> Hacl.Streaming.Interface.block Prims.unit
{ "end_col": 34, "end_line": 617, "start_col": 2, "start_line": 563 }
FStar.Pervasives.Lemma
val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a))
[ { "abbrev": true, "full_module": "Hacl.Blake2b_32", "short_module": "Blake2b32" }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "Blake2s32" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "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 } ]
false
let spec_is_incremental a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a)
val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) let spec_is_incremental a kk k input0 =
false
null
false
let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let s = init_s a kk in repeati_split_at_eq a s input; let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (s1 == s2); S.lemma_eq_intro (S.slice input (S.length input - l_last) (S.length input)) last; S.lemma_eq_intro (S.slice last (S.length last - l_last) (S.length last)) last; Spec.Blake2.Alternative.lemma_spec_equivalence_update a kk k input0 s; assert (U32.v (output_len a) = output_size a)
{ "checked_file": "Hacl.Streaming.Blake2.fst.checked", "dependencies": [ "Spec.Blake2.Alternative.fsti.checked", "Spec.Blake2.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Interface.fsti.checked", "Hacl.Streaming.Functor.fsti.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "Hacl.Blake2b_32.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Streaming.Blake2.fst" }
[ "lemma" ]
[ "Hacl.Streaming.Blake2.alg", "Hacl.Streaming.Blake2.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Streaming.Blake2.max_key", "Hacl.Streaming.Blake2.lbytes", "FStar.Seq.Base.seq", "Hacl.Streaming.Blake2.uint8", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Hacl.Streaming.Blake2.max_input_length", "Prims.bool", "Prims.op_Addition", "Spec.Blake2.size_block", "Prims.nat", "Lib.UpdateMulti.uint8", "Prims._assert", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Hacl.Streaming.Blake2.output_len", "Hacl.Streaming.Blake2.output_size", "Prims.unit", "Spec.Blake2.Alternative.lemma_spec_equivalence_update", "FStar.Seq.Base.lemma_eq_intro", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "Prims.eq2", "Spec.Blake2.state", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.Blake2.wt", "Lib.IntTypes.SEC", "Lib.LoopCombinators.repeati", "Prims.l_and", "Prims.op_LessThan", "Prims.op_Division", "Lib.Sequence.length", "Lib.IntTypes.U8", "Spec.Blake2.max_limb", "Spec.Blake2.blake2_update1", "Hacl.Streaming.Blake2.repeati_split_at_eq", "Hacl.Streaming.Blake2.t", "Hacl.Streaming.Blake2.init_s", "FStar.Pervasives.Native.tuple2", "Lib.UpdateMulti.split_at_last_lazy", "Hacl.Streaming.Blake2.block_len", "Prims.op_Multiply", "Spec.Blake2.split", "FStar.Seq.Base.append", "Prims.op_GreaterThan", "Spec.Blake2.blake2_key_block", "FStar.Seq.Base.empty" ]
[]
module Hacl.Streaming.Blake2 module HS = FStar.HyperStack module B = LowStar.Buffer module G = FStar.Ghost module S = FStar.Seq module LS = Lib.Sequence module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module F = Hacl.Streaming.Functor module I = Hacl.Streaming.Interface module ST = FStar.HyperStack.ST open FStar.Mul module Loops = Lib.LoopCombinators /// Opening a bunch of modules for Blake2 /// ===================================== inline_for_extraction noextract let uint8 = Lib.IntTypes.uint8 inline_for_extraction noextract let uint32 = Lib.IntTypes.uint32 unfold noextract let size_nat = Lib.IntTypes.size_nat unfold noextract let max_key = Spec.Blake2.max_key unfold noextract let lbytes = Lib.ByteSequence.lbytes module Spec = Spec.Blake2 module Core = Hacl.Impl.Blake2.Core open Hacl.Impl.Blake2.Generic module Blake2s32 = Hacl.Blake2s_32 module Blake2b32 = Hacl.Blake2b_32 /// An instance of the stateful type class for blake2 /// ================================================= #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" inline_for_extraction noextract let index = unit inline_for_extraction noextract let alg = Spec.alg inline_for_extraction noextract let m_spec = Core.m_spec /// The stateful state: (wv, hash) inline_for_extraction noextract let s (a : alg) (m : m_spec) = Core.(state_p a m & state_p a m) inline_for_extraction noextract let t (a : alg) = Spec.state a (* In the internal state, we keep wv, the working vector. It's essentially temporary scratch space that the Blake2 implementation expects to receive. (Why is the implementation not performing its own stack allocations? Don't know!) *) inline_for_extraction noextract let get_wv (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with wv, _ -> wv inline_for_extraction noextract let get_state_p (#a : alg) (#m : m_spec) (s : s a m) : Tot (Core.state_p a m) = match s with _, p -> p (* But the working vector is not reflected in the state at all -- it doesn't have meaningful specification contents. *) inline_for_extraction noextract let state_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (Spec.state a) = Core.state_v h (get_state_p s) inline_for_extraction noextract let s_v (#a : alg) (#m : m_spec) (h : HS.mem) (s : s a m) : GTot (t a) = state_v h s /// Small helper which facilitates inferencing implicit arguments for buffer /// operations inline_for_extraction noextract let state_to_lbuffer (#a : alg) (#m : m_spec) (s : Core.state_p a m) : B.lbuffer (Core.element_t a m) (4 * U32.v (Core.row_len a m)) = s inline_for_extraction noextract let stateful_blake2 (a : alg) (m : m_spec) : I.stateful unit = I.Stateful (fun () -> s a m) (* s *) (* footprint *) (fun #_ _ acc -> let wv, b = acc in B.loc_union (B.loc_addr_of_buffer (state_to_lbuffer wv)) (B.loc_addr_of_buffer (state_to_lbuffer b))) (* freeable *) (fun #_ _ acc -> let wv, b = acc in B.freeable (state_to_lbuffer wv) /\ B.freeable (state_to_lbuffer b)) (* invariant *) (fun #_ h acc -> let wv, b = acc in B.live h (state_to_lbuffer wv) /\ B.live h (state_to_lbuffer b) /\ B.disjoint (state_to_lbuffer wv) (state_to_lbuffer b)) (fun () -> t a) (* t *) (fun () h acc -> s_v h acc) (* v *) (fun #_ h acc -> let wv, b = acc in ()) (* invariant_loc_in_footprint *) (fun #_ l acc h0 h1 -> let wv, b = acc in ()) (* frame_invariant *) (fun #_ _ _ _ _ -> ()) (* frame_freeable *) (* alloca *) (fun () -> let wv = Core.alloc_state a m in let b = Core.alloc_state a m in wv, b) (* create_in *) (fun () r -> let wv = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in let b = B.malloc r (Core.zero_element a m) U32.(4ul *^ Core.row_len a m) in wv, b) (* free *) (fun _ acc -> match acc with wv, b -> B.free (state_to_lbuffer wv); B.free (state_to_lbuffer b)) (* copy *) (fun _ src dst -> match src with src_wv, src_b -> match dst with src_wv, dst_b -> B.blit (state_to_lbuffer src_b) 0ul (state_to_lbuffer dst_b) 0ul U32.(4ul *^ Core.row_len a m)) /// Stateful key /// ============ inline_for_extraction noextract let key_size (a : alg) = kk:nat{kk <= Spec.max_key a} inline_for_extraction noextract let key_size_t (a : alg) = key_size:U32.t{U32.v key_size <= Spec.max_key a} /// Defining stateful keys inline_for_extraction noextract let stateful_key_t (a : alg) (key_size : key_size a) : Type = if key_size = 0 then unit else b:B.buffer uint8 { B.length b == key_size} inline_for_extraction noextract let buffer_to_stateful_key_t (a : alg) (kk : key_size a{kk > 0}) (k : B.buffer uint8 { B.length k == kk }) : Tot (stateful_key_t a kk) = k inline_for_extraction noextract let unit_to_stateful_key_t (a : alg) : Tot (stateful_key_t a 0) = () /// The ``has_key`` parameter is meta /// TODO: this definition could be moved to Hacl.Streaming.Interface, it could /// be pretty useful in other situations as it generalizes ``stateful_buffer`` in /// the case the length is zero. Note that rather than being unit, the type could /// be buffer too (and we would use null whenever needed). inline_for_extraction noextract let stateful_key (a : alg) (kk : key_size a) : I.stateful unit = I.Stateful (fun _ -> stateful_key_t a kk) (* footprint *) (fun #_ h s -> if kk = 0 then B.loc_none else B.loc_addr_of_buffer (s <: B.buffer uint8)) (* freeable *) (fun #_ h s -> if kk = 0 then True else B.freeable (s <: B.buffer uint8)) (* invariant *) (fun #_ h s -> if kk = 0 then True else B.live h (s <: B.buffer uint8)) (fun _ -> s:S.seq uint8 { S.length s == kk }) (fun _ h s -> if kk = 0 then Seq.empty else B.as_seq h (s <: B.buffer uint8)) (fun #_ h s -> ()) (* invariant_loc_in_footprint *) (fun #_ l s h0 h1 -> ()) (* frame_invariant *) (fun #_ l s h0 h1 -> ()) (* frame_freeable *) (* alloca *) (fun () -> if kk > 0 then buffer_to_stateful_key_t a kk (B.alloca (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* create_in *) (fun () r -> if kk > 0 then buffer_to_stateful_key_t a kk (B.malloc r (Lib.IntTypes.u8 0) (U32.uint_to_t kk)) else unit_to_stateful_key_t a) (* free *) (fun _ s -> if kk > 0 then B.free (s <: B.buffer uint8) else ()) (* copy *) (fun _ s_src s_dst -> if kk > 0 then B.blit (s_src <: B.buffer uint8) 0ul (s_dst <: B.buffer uint8) 0ul (U32.uint_to_t kk) else ()) inline_for_extraction noextract let stateful_key_to_buffer (#a : alg) (#kk : key_size a) (key : stateful_key_t a kk) : b:B.buffer uint8 { B.length b = kk } = if kk = 0 then B.null #uint8 else key inline_for_extraction noextract let k = stateful_key /// Actual functor instantiation /// ============================ /// Small helpers /// ------------- noextract let max_input_length (a : alg) : n:nat { n <= Spec.max_limb a /\ n > Spec.size_block a } = assert_norm (pow2 64 < pow2 128); pow2 64 - 1 noextract inline_for_extraction let max_input_len (a: alg): (x:U64.t { U64.v x == max_input_length a }) = 0xffffffffffffffffUL inline_for_extraction noextract let block (a : alg) = (block: S.seq uint8 { S.length block = Spec.size_block a }) inline_for_extraction noextract let block_len (a : alg) : U32.t = Core.size_block a inline_for_extraction noextract let output_size (a : alg) : nat = Spec.max_output a inline_for_extraction noextract let output_len (a : alg) = U32.uint_to_t (output_size a) /// From the functor-provided previous length (uint64, public) to a suitable /// type for Blake2 (secret uint64/uint128) inline_for_extraction noextract let blake2_prevlen (a : alg) (prevlen : U64.t{ U64.v prevlen <= max_input_length a}) : x:Spec.limb_t a { Lib.IntTypes.uint_v x = U64.v prevlen } = let open Lib.IntTypes in match a with | Spec.Blake2S -> to_u64 #U64 #PUB prevlen | Spec.Blake2B -> [@inline_let] let x : uint64 = to_u64 #U64 #PUB prevlen in Lib.IntTypes.cast U128 SEC x /// Specs /// ----- noextract let init_s (a : alg) (kk : size_nat{kk <= max_key a}) : Tot (t a) = Spec.blake2_init_hash a kk (output_size a) noextract let update_multi_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ prevlen + S.length input <= max_input_length a /\ S.length input % Spec.size_block a = 0 }) : Tot (t a) = let nb = S.length input / U32.v (block_len a) in Lib.LoopCombinators.repeati nb (Spec.blake2_update1 a prevlen input) acc noextract let update_last_s (#a : alg) (acc : t a) (prevlen : nat{prevlen % Spec.size_block a = 0}) (input : Seq.seq uint8{ S.length input + prevlen <= max_input_length a /\ S.length input <= Spec.size_block a }) : Tot (t a) = Spec.blake2_update_last a prevlen (S.length input) input acc noextract let finish_s (#a : alg) (acc : t a) : output : S.seq uint8 { S.length output = U32.v (output_len a) } = Spec.blake2_finish a acc (U32.v (output_len a)) noextract let spec_s (a : alg) (kk : size_nat{kk <= max_key a}) (key : lbytes kk) (input : S.seq uint8{if kk = 0 then S.length input <= max_input_length a else S.length input + Spec.size_block a <= max_input_length a}) = Spec.blake2 a input kk key (output_size a) /// Interlude for spec proofs /// ------------------------- val update_multi_zero: #a : alg -> acc:t a -> prevlen:nat{prevlen % Spec.size_block a = 0} -> Lemma (requires (prevlen <= max_input_length a)) (ensures (update_multi_s #a acc prevlen S.empty == acc)) let update_multi_zero #a acc prevlen = Lib.LoopCombinators.eq_repeati0 (0 / U32.v (block_len a)) (Spec.blake2_update1 a prevlen S.empty) acc #push-options "--z3cliopt smt.arith.nl=false" val update_multi_associative: #a : alg -> acc: t a -> prevlen1:nat -> prevlen2:nat -> input1:S.seq uint8 -> input2:S.seq uint8 -> Lemma (requires ( (**) Math.Lemmas.pos_times_pos_is_pos Spec.size_block_w (Spec.size_word a); prevlen1 % Spec.size_block a = 0 /\ S.length input1 % Spec.size_block a = 0 /\ S.length input2 % Spec.size_block a = 0 /\ prevlen1 + S.length input1 + S.length input2 <= max_input_length a /\ prevlen2 = prevlen1 + S.length input1)) (ensures ( let input = S.append input1 input2 in S.length input % Spec.size_block a = 0 /\ prevlen2 % Spec.size_block a = 0 /\ update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2 == update_multi_s acc prevlen1 input)) #pop-options #push-options "--z3rlimit 400" let update_multi_associative #a acc prevlen1 prevlen2 input1 input2 = let input = S.append input1 input2 in let nb = S.length input / U32.v (block_len a) in let nb1 = S.length input1 / U32.v (block_len a) in let nb2 = S.length input2 / U32.v (block_len a) in let f = Spec.blake2_update1 a prevlen1 input in let f1 = Spec.blake2_update1 a prevlen1 input1 in let f2 = Spec.blake2_update1 a prevlen2 input2 in let aux1 (i:nat{i < nb1}) (acc:t a) : Lemma (f i acc == f1 i acc) = assert (Spec.get_blocki a input i `Seq.equal` Spec.get_blocki a input1 i) in let aux2 (i:nat{i < nb2}) (acc:t a) : Lemma (f2 i acc == f (i + nb1) acc) = assert (Spec.get_blocki a input2 i `Seq.equal` Spec.get_blocki a input (i + nb1)) in let open Lib.LoopCombinators in let open Lib.Sequence.Lemmas in calc (==) { update_multi_s (update_multi_s acc prevlen1 input1) prevlen2 input2; (==) { } repeati nb2 f2 (repeati nb1 f1 acc); (==) { Classical.forall_intro_2 aux1; repeati_extensionality nb1 f1 f acc } repeati nb2 f2 (repeati nb1 f acc); (==) { repeati_def nb1 f acc; repeati_def nb2 f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right 0 nb2 (fixed_a (t a)) f2 (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { Classical.forall_intro_2 aux2; repeat_gen_right_extensionality nb2 nb1 (fixed_a (t a)) (fixed_a (t a)) f2 f (repeat_right 0 nb1 (fixed_a (t a)) f acc) } repeat_right nb1 (nb1 + nb2) (fixed_a (t a)) f (repeat_right 0 nb1 (fixed_a (t a)) f acc); (==) { repeat_right_plus 0 nb1 nb (fixed_a (t a)) f acc; repeati_def nb f acc } repeati nb f acc; (==) { } update_multi_s acc prevlen1 input; } #pop-options /// A helper function: the hash incremental function defined with the functions /// locally defined (with a signature adapted to the functor). noextract val blake2_hash_incremental_s : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> output:S.seq uint8 { S.length output = output_size a } #push-options "--z3cliopt smt.arith.nl=false" let blake2_hash_incremental_s a kk k input0 = let key_block = if kk > 0 then Spec.blake2_key_block a kk k else S.empty in let key_block_len = S.length key_block in let input = Seq.append key_block input0 in assert (key_block_len = (if kk = 0 then 0 else Spec.size_block a)); (**) Math.Lemmas.modulo_lemma 0 (U32.v (block_len a)); let bs, l = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let acc1 = init_s a kk in let acc2 = update_multi_s #a acc1 0 bs in let acc3 = update_last_s #a acc2 (S.length bs) l in let acc4 = finish_s #a acc3 in acc4 #pop-options #push-options "--z3cliopt smt.arith.nl=false" val repeati_split_at_eq : a : alg -> s : t a -> input:S.seq uint8 { S.length input <= max_input_length a } -> Lemma( let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in n_blocks = Lib.Sequence.length blocks / Spec.size_block a /\ // This is necessary for type-checking Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 input) s == Lib.LoopCombinators.repeati n_blocks (Spec.blake2_update1 a 0 blocks) s) #pop-options #push-options "--z3cliopt smt.arith.nl=false" let repeati_split_at_eq a s input = let n_blocks, l_last = Spec.split a (S.length input) in let blocks, last = Lib.UpdateMulti.split_at_last_lazy (U32.v (block_len a)) input in let f = Spec.blake2_update1 a 0 input in let g = Spec.blake2_update1 a 0 blocks in let s1 = Lib.LoopCombinators.repeati n_blocks f s in assert (Lib.Sequence.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.cancel_mul_div n_blocks (Spec.size_block a); assert (n_blocks = Lib.Sequence.length blocks / Spec.size_block a); assert (Lib.Sequence.length blocks <= max_input_length a); let s2 = Lib.LoopCombinators.repeati n_blocks g s in assert (input `Seq.equal` Seq.append blocks last); assert (S.length input = S.length blocks + S.length last); introduce forall (i:nat{i < n_blocks}). (Spec.get_blocki a input i) `S.equal` (Spec.get_blocki a blocks i) with begin let b0 = Spec.get_blocki a input i in let b1 = Spec.get_blocki a blocks i in assert (S.length blocks = n_blocks * Spec.size_block a); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) (i + 1) n_blocks; assert ((i + 1) * Spec.size_block a <= S.length blocks); Math.Lemmas.lemma_mult_le_right (Spec.size_block a) i n_blocks; assert (i * Spec.size_block a <= S.length blocks); Math.Lemmas.distributivity_add_left i 1 (Spec.size_block a); assert ((i + 1) * Spec.size_block a = i * Spec.size_block a + Spec.size_block a); introduce forall (j: nat{j < Spec.size_block a}). S.index b0 j == S.index b1 j with begin assert (i * Spec.size_block a + j < i * Spec.size_block a + Spec.size_block a); Math.Lemmas.nat_times_nat_is_nat i (Spec.size_block a); S.lemma_index_slice input (i * Spec.size_block a) ((i + 1) * Spec.size_block a) j; assert (S.index b0 j == S.index input (j + (i * Spec.size_block a))) end end; assert (forall (i:nat{i < n_blocks}) acc. f i acc == g i acc); Lib.Sequence.Lemmas.repeati_extensionality n_blocks f g s #pop-options val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a)) #restart-solver
false
false
Hacl.Streaming.Blake2.fst
{ "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": false, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val spec_is_incremental : a : alg -> kk: size_nat{kk <= max_key a} -> k: lbytes kk -> input:S.seq uint8 { if kk = 0 then S.length input <= max_input_length a else S.length input + (Spec.size_block a) <= max_input_length a } -> Lemma( blake2_hash_incremental_s a kk k input == Spec.blake2 a input kk k (output_size a))
[]
Hacl.Streaming.Blake2.spec_is_incremental
{ "file_name": "code/streaming/Hacl.Streaming.Blake2.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Streaming.Blake2.alg -> kk: Hacl.Streaming.Blake2.size_nat{kk <= Hacl.Streaming.Blake2.max_key a} -> k: Hacl.Streaming.Blake2.lbytes kk -> input: FStar.Seq.Base.seq Hacl.Streaming.Blake2.uint8 { (match kk = 0 with | true -> FStar.Seq.Base.length input <= Hacl.Streaming.Blake2.max_input_length a | _ -> FStar.Seq.Base.length input + Spec.Blake2.size_block a <= Hacl.Streaming.Blake2.max_input_length a) <: Type0 } -> FStar.Pervasives.Lemma (ensures Hacl.Streaming.Blake2.blake2_hash_incremental_s a kk k input == Spec.Blake2.blake2 a input kk k (Hacl.Streaming.Blake2.output_size a))
{ "end_col": 47, "end_line": 485, "start_col": 39, "start_line": 468 }
Prims.Tot
val validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r + 1))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x)))))
val validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r + 1)) let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r + 1)) =
false
null
false
u: (bitsum'_key_type b -> Tot (Type u#r)) -> f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (u x))) -> v: (x: bitsum'_key_type b -> Tot (validator (dsnd (f x)))) -> x: parse_filter_refine (filter_bitsum' b) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x)))))
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_key_type", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.bitsum'_key_of_t", "LowParse.Spec.BitSum.synth_bitsum'" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from)
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r + 1))
[]
LowParse.Low.BitSum.validate_bitsum_cases_t
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Spec.BitSum.bitsum' cl from -> Type
{ "end_col": 69, "end_line": 47, "start_col": 2, "start_line": 43 }
Prims.Tot
val validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ()))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos
val validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) =
false
null
false
fun u f v x #rrel #rel sl pos -> v () sl pos
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitStop", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Low.BitSum.validate_bitsum_cases_t" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t)
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ()))
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitstop
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> LowParse.Low.BitSum.validate_bitsum_cases_t (LowParse.Spec.BitSum.BitStop ())
{ "end_col": 13, "end_line": 56, "start_col": 2, "start_line": 55 }
Prims.Tot
val mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b)
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let rec mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b) = match b with | BitStop _ -> validate_bitsum_cases_bitstop cl | BitField sz rest -> validate_bitsum_cases_bitfield cl bitsum'_size sz rest (mk_validate_bitsum_cases_t' rest) | BitSum' key key_size e payload -> validate_bitsum_cases_bitsum'_intro cl bitsum'_size key key_size e payload (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload [] e (mk_validate_bitsum_cases_t' #tot #t #cl #(bitsum'_size - key_size)))
val mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b) let rec mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b) =
false
null
false
match b with | BitStop _ -> validate_bitsum_cases_bitstop cl | BitField sz rest -> validate_bitsum_cases_bitfield cl bitsum'_size sz rest (mk_validate_bitsum_cases_t' rest) | BitSum' key key_size e payload -> validate_bitsum_cases_bitsum'_intro cl bitsum'_size key key_size e payload (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload [] e (mk_validate_bitsum_cases_t' #tot #t #cl #(bitsum'_size - key_size)))
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total", "" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "LowParse.Low.BitSum.validate_bitsum_cases_bitstop", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Low.BitSum.validate_bitsum_cases_bitfield", "LowParse.Low.BitSum.mk_validate_bitsum_cases_t'", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_intro", "LowParse.Low.BitSum.mk_validate_bitsum_cases_bitsum'_t'", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "LowParse.Low.BitSum.validate_bitsum_cases_t" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *)) #push-options "--z3rlimit 32" inline_for_extraction let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun u f v x xr #rrel #rel sl pos -> // [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x sl pos else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) (mk_validate_bitsum_cases_t': (* universe-polymorphic mutually recursive functions must be "split off" cf. https://github.com/FStarLang/FStar/issues/1480#issuecomment-623260544 *) (b: bitsum' cl (bitsum'_size - key_size) { b << BitSum' key key_size e payload }) -> Tot (validate_bitsum_cases_t u#r b) ) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in validate_bitsum_cases_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in validate_bitsum_cases_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_validate_bitsum_cases_t' (payload k)) (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q mk_validate_bitsum_cases_t') [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b)
false
false
LowParse.Low.BitSum.fst
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b)
[ "recursion" ]
LowParse.Low.BitSum.mk_validate_bitsum_cases_t'
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> Prims.Tot (LowParse.Low.BitSum.validate_bitsum_cases_t b)
{ "end_col": 229, "end_line": 258, "start_col": 2, "start_line": 254 }
Prims.Tot
val validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p))
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) ()
val validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) =
false
null
false
synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) ()
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "LowParse.Low.Base.leaf_reader", "LowParse.Spec.BitSum.filter_bitsum'_t", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.Combinators.parse_filter", "LowParse.Low.Combinators.validate_filter", "Prims.bool", "Prims.eq2", "LowParse.Spec.BitSum.synth_bitsum'", "Prims.unit", "LowParse.Spec.BitSum.synth_bitsum'_injective", "LowParse.Spec.BitSum.parse_bitsum'" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b)
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p))
[]
LowParse.Low.BitSum.validate_bitsum'
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Spec.BitSum.bitsum' cl tot -> v: LowParse.Low.Base.validator p -> r: LowParse.Low.Base.leaf_reader p -> phi: LowParse.Spec.BitSum.filter_bitsum'_t b -> LowParse.Low.Base.validator (LowParse.Spec.BitSum.parse_bitsum' b p)
{ "end_col": 6, "end_line": 30, "start_col": 2, "start_line": 22 }
Prims.Tot
val validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos
val validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) =
false
null
false
fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Low.BitSum.validate_bitsum_cases_t", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitField", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Spec.BitSum.coerce" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest)
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest))
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitfield
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} -> rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) -> phi: LowParse.Low.BitSum.validate_bitsum_cases_t rest -> LowParse.Low.BitSum.validate_bitsum_cases_t (LowParse.Spec.BitSum.BitField sz rest)
{ "end_col": 7, "end_line": 75, "start_col": 2, "start_line": 68 }
Prims.Tot
val validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) : Tot (Type u#(r + 1))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x)))))
val validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) : Tot (Type u#(r + 1)) let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) : Tot (Type u#(r + 1)) =
false
null
false
u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r)) -> f: (x: bitsum'_key_type (BitSum' key key_size e payload) -> Tot (k: parser_kind & parser k (u x)) ) -> v: (x: bitsum'_key_type (BitSum' key key_size e payload) -> Tot (validator (dsnd (f x)))) -> x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~(list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) } -> xr: t{xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size} -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x)))))
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.eq2", "FStar.List.Tot.Base.append", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.l_not", "LowParse.Spec.Enum.list_mem", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.snd", "LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs", "LowParse.Spec.BitSum.bitsum'_key_of_t", "LowParse.Spec.BitSum.synth_bitsum'" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } )
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) : Tot (Type u#(r + 1))
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) -> l2: Prims.list (key * LowParse.BitFields.bitfield cl key_size) {e == l1 @ l2} -> Type
{ "end_col": 131, "end_line": 123, "start_col": 2, "start_line": 118 }
Prims.Tot
val validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e [])
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *))
val validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) =
false
null
false
(fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic)
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "Prims.squash", "Prims.eq2", "Prims.list", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.append", "Prims.Nil", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.l_not", "LowParse.Spec.Enum.list_mem", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.snd", "LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Low.ErrorCode.validator_error_generic", "Prims.unit", "Prims._assert", "Prims.l_False", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` []))
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e [])
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_nil
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> h: Prims.squash (e == e @ []) -> LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t cl bitsum'_size key key_size e payload e []
{ "end_col": 40, "end_line": 155, "start_col": 2, "start_line": 153 }
Prims.Tot
val validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos
val validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) =
false
null
false
fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs", "LowParse.Low.BitSum.validate_bitsum_cases_t" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e)
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload))
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_intro
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> phi: LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t cl bitsum'_size key key_size e payload [] e -> LowParse.Low.BitSum.validate_bitsum_cases_t (LowParse.Spec.BitSum.BitSum' key key_size e payload)
{ "end_col": 25, "end_line": 139, "start_col": 2, "start_line": 137 }
Prims.Tot
val mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) (mk_validate_bitsum_cases_t': (b: bitsum' cl (bitsum'_size - key_size) {b << BitSum' key key_size e payload} -> Tot (validate_bitsum_cases_t u#r b))) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload;l2])
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) (mk_validate_bitsum_cases_t': (* universe-polymorphic mutually recursive functions must be "split off" cf. https://github.com/FStarLang/FStar/issues/1480#issuecomment-623260544 *) (b: bitsum' cl (bitsum'_size - key_size) { b << BitSum' key key_size e payload }) -> Tot (validate_bitsum_cases_t u#r b) ) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in validate_bitsum_cases_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in validate_bitsum_cases_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_validate_bitsum_cases_t' (payload k)) (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q mk_validate_bitsum_cases_t')
val mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) (mk_validate_bitsum_cases_t': (b: bitsum' cl (bitsum'_size - key_size) {b << BitSum' key key_size e payload} -> Tot (validate_bitsum_cases_t u#r b))) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload;l2]) let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) (mk_validate_bitsum_cases_t': (b: bitsum' cl (bitsum'_size - key_size) {b << BitSum' key key_size e payload} -> Tot (validate_bitsum_cases_t u#r b))) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload;l2]) =
false
null
false
bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@@ inline_let ]let _ = L.append_l_nil l1 in validate_bitsum_cases_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@@ inline_let ]let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in validate_bitsum_cases_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_validate_bitsum_cases_t' (payload k)) (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q mk_validate_bitsum_cases_t')
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total", "" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.eq2", "FStar.List.Tot.Base.append", "Prims.precedes", "LowParse.Spec.BitSum.BitSum'", "LowParse.Low.BitSum.validate_bitsum_cases_t", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_nil", "Prims.unit", "FStar.List.Tot.Properties.append_l_nil", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_cons", "LowParse.Low.BitSum.mk_validate_bitsum_cases_bitsum'_t'", "Prims.Cons", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "FStar.List.Tot.Properties.append_assoc", "LowParse.Spec.Enum.enum_repr_of_key_append_cons", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t", "LowParse.Spec.BitSum.bitsum_wellfoundedness" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *)) #push-options "--z3rlimit 32" inline_for_extraction let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun u f v x xr #rrel #rel sl pos -> // [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x sl pos else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) (mk_validate_bitsum_cases_t': (* universe-polymorphic mutually recursive functions must be "split off" cf. https://github.com/FStarLang/FStar/issues/1480#issuecomment-623260544 *) (b: bitsum' cl (bitsum'_size - key_size) { b << BitSum' key key_size e payload }) -> Tot (validate_bitsum_cases_t u#r b) ) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2)
false
false
LowParse.Low.BitSum.fst
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) {e == l1 `L.append` l2}) (mk_validate_bitsum_cases_t': (b: bitsum' cl (bitsum'_size - key_size) {b << BitSum' key key_size e payload} -> Tot (validate_bitsum_cases_t u#r b))) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload;l2])
[ "recursion" ]
LowParse.Low.BitSum.mk_validate_bitsum_cases_bitsum'_t'
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) -> l2: Prims.list (key * LowParse.BitFields.bitfield cl key_size) {e == l1 @ l2} -> mk_validate_bitsum_cases_t': ( b: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) {b << LowParse.Spec.BitSum.BitSum' key key_size e payload} -> LowParse.Low.BitSum.validate_bitsum_cases_t b) -> Prims.Tot (LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t cl bitsum'_size key key_size e payload l1 l2)
{ "end_col": 137, "end_line": 242, "start_col": 2, "start_line": 228 }
FStar.Pervasives.Lemma
val valid_bitsum_elim (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid p h sl pos /\ (let x = contents p h sl pos in filter_bitsum' b x == true /\ (let tg = synth_bitsum' b x in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos p h sl pos in valid (dsnd (f k)) h sl pos1 /\ valid_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (get_valid_pos (dsnd (f k)) h sl pos1) /\ (let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == synth_case.f tg y /\ y == synth_case.g tg x)))))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let valid_bitsum_elim (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos )) (ensures ( valid p h sl pos /\ ( let x = contents p h sl pos in filter_bitsum' b x == true /\ ( let tg = synth_bitsum' b x in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos p h sl pos in valid (dsnd (f k)) h sl pos1 /\ valid_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (get_valid_pos (dsnd (f k)) h sl pos1) /\ ( let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == synth_case.f tg y /\ y == synth_case.g tg x ))))) = valid_bitsum_elim' b tag_of_data type_of_tag synth_case p f h sl pos; synth_bitsum'_injective b; assert (valid ((p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b) h sl pos); valid_synth h (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) sl pos; valid_filter h p (filter_bitsum' b) sl pos; let tg = synth_bitsum' b (contents p h sl pos) in let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in assert (tg == tag_of_data x); assert (x == synth_case.f tg y); synth_case.f_g_eq tg x; synth_case.f_inj tg (synth_case.g tg x) y
val valid_bitsum_elim (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid p h sl pos /\ (let x = contents p h sl pos in filter_bitsum' b x == true /\ (let tg = synth_bitsum' b x in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos p h sl pos in valid (dsnd (f k)) h sl pos1 /\ valid_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (get_valid_pos (dsnd (f k)) h sl pos1) /\ (let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == synth_case.f tg y /\ y == synth_case.g tg x))))) let valid_bitsum_elim (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid p h sl pos /\ (let x = contents p h sl pos in filter_bitsum' b x == true /\ (let tg = synth_bitsum' b x in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos p h sl pos in valid (dsnd (f k)) h sl pos1 /\ valid_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (get_valid_pos (dsnd (f k)) h sl pos1) /\ (let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == synth_case.f tg y /\ y == synth_case.g tg x))))) =
false
null
true
valid_bitsum_elim' b tag_of_data type_of_tag synth_case p f h sl pos; synth_bitsum'_injective b; assert (valid ((p `parse_filter` (filter_bitsum' b)) `parse_synth` (synth_bitsum' b)) h sl pos); valid_synth h (p `parse_filter` (filter_bitsum' b)) (synth_bitsum' b) sl pos; valid_filter h p (filter_bitsum' b) sl pos; let tg = synth_bitsum' b (contents p h sl pos) in let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in assert (tg == tag_of_data x); assert (x == synth_case.f tg y); synth_case.f_g_eq tg x; synth_case.f_inj tg (synth_case.g tg x) y
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.synth_case_t", "LowParse.Spec.Base.parser", "Prims.dtuple2", "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Spec.BitSum.__proj__SynthCase__item__f_inj", "LowParse.Spec.BitSum.__proj__SynthCase__item__g", "Prims.unit", "LowParse.Spec.BitSum.__proj__SynthCase__item__f_g_eq", "Prims._assert", "Prims.eq2", "LowParse.Spec.BitSum.__proj__SynthCase__item__f", "LowParse.Low.Base.Spec.contents", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.BitSum.parse_bitsum_kind", "LowParse.Spec.BitSum.parse_bitsum", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BitSum.parse_bitsum'", "LowParse.Spec.BitSum.bitsum'_key_of_t", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Low.Combinators.valid_filter", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Low.Combinators.valid_synth", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.BitSum.synth_bitsum'_injective", "LowParse.Low.BitSum.valid_bitsum_elim'", "Prims.squash", "Prims.l_and", "Prims.bool", "LowParse.Low.Base.Spec.valid_pos", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *)) #push-options "--z3rlimit 32" inline_for_extraction let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun u f v x xr #rrel #rel sl pos -> // [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x sl pos else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) (mk_validate_bitsum_cases_t': (* universe-polymorphic mutually recursive functions must be "split off" cf. https://github.com/FStarLang/FStar/issues/1480#issuecomment-623260544 *) (b: bitsum' cl (bitsum'_size - key_size) { b << BitSum' key key_size e payload }) -> Tot (validate_bitsum_cases_t u#r b) ) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in validate_bitsum_cases_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in validate_bitsum_cases_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_validate_bitsum_cases_t' (payload k)) (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q mk_validate_bitsum_cases_t') [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b) = match b with | BitStop _ -> validate_bitsum_cases_bitstop cl | BitField sz rest -> validate_bitsum_cases_bitfield cl bitsum'_size sz rest (mk_validate_bitsum_cases_t' rest) | BitSum' key key_size e payload -> validate_bitsum_cases_bitsum'_intro cl bitsum'_size key key_size e payload (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload [] e (mk_validate_bitsum_cases_t' #tot #t #cl #(bitsum'_size - key_size))) #push-options "--z3rlimit 64" #restart-solver inline_for_extraction let validate_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (vf: (x: bitsum'_key_type b) -> Tot (validator (dsnd (f x)))) (vs: validate_bitsum_cases_t b) : Tot (validator (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl (uint64_to_uint32 pos); parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl (uint64_to_uint32 pos)); valid_facts (parse_bitsum' b p) h sl (uint64_to_uint32 pos) in let pos1 = validate_bitsum' b v r phi sl pos in if is_error pos1 then pos1 else [@inline_let] let _ = synth_bitsum'_injective b; parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (bytes_of_slice_from h sl (uint64_to_uint32 pos)); parse_filter_eq p (filter_bitsum' b) (bytes_of_slice_from h sl (uint64_to_uint32 pos)); valid_facts p h sl (uint64_to_uint32 pos) in let x = r sl (uint64_to_uint32 pos) in [@inline_let] let _ = let y = synth_bitsum' b x in let tg = bitsum'_key_of_t b y in parse_synth_eq (dsnd (f tg)) (synth_case.f y) (bytes_of_slice_from h sl (uint64_to_uint32 pos1)); valid_facts (dsnd (f tg)) h sl (uint64_to_uint32 pos1) in vs (type_of_tag) f vf x sl pos1 #pop-options let valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos) ))) (ensures ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1) )) = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1 #pop-options let valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos )) (ensures ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ ( let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1) )))) = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1; valid_bitsum_intro b tag_of_data type_of_tag synth_case p f h sl pos let valid_bitsum_elim (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos )) (ensures ( valid p h sl pos /\ ( let x = contents p h sl pos in filter_bitsum' b x == true /\ ( let tg = synth_bitsum' b x in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos p h sl pos in valid (dsnd (f k)) h sl pos1 /\ valid_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (get_valid_pos (dsnd (f k)) h sl pos1) /\ ( let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == synth_case.f tg y /\ y == synth_case.g tg x
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bitsum_elim (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid p h sl pos /\ (let x = contents p h sl pos in filter_bitsum' b x == true /\ (let tg = synth_bitsum' b x in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos p h sl pos in valid (dsnd (f k)) h sl pos1 /\ valid_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (get_valid_pos (dsnd (f k)) h sl pos1) /\ (let x = contents (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == synth_case.f tg y /\ y == synth_case.g tg x)))))
[]
LowParse.Low.BitSum.valid_bitsum_elim
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Spec.BitSum.bitsum' cl tot -> tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) -> type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) -> synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag -> p: LowParse.Spec.Base.parser kt t -> f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) -> h: FStar.Monotonic.HyperStack.mem -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.BitSum.parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos) (ensures LowParse.Low.Base.Spec.valid p h sl pos /\ (let x = LowParse.Low.Base.Spec.contents p h sl pos in LowParse.Spec.BitSum.filter_bitsum' b x == true /\ (let tg = LowParse.Spec.BitSum.synth_bitsum' b x in let k = LowParse.Spec.BitSum.bitsum'_key_of_t b tg in let pos1 = LowParse.Low.Base.Spec.get_valid_pos p h sl pos in LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (f k)) h sl pos1 /\ LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.BitSum.parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (LowParse.Low.Base.Spec.get_valid_pos (FStar.Pervasives.dsnd (f k)) h sl pos1) /\ (let x = LowParse.Low.Base.Spec.contents (LowParse.Spec.BitSum.parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos in let y = LowParse.Low.Base.Spec.contents (FStar.Pervasives.dsnd (f k)) h sl pos1 in tg == tag_of_data x /\ x == SynthCase?.f synth_case tg y /\ y == SynthCase?.g synth_case tg x))))
{ "end_col": 43, "end_line": 442, "start_col": 2, "start_line": 428 }
Prims.Tot
val validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x}))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: (k: enum_key e -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos
val validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x}))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: (k: enum_key e -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x}))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: (k: enum_key e -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) =
false
null
false
fun u f v x_ #rrel #rel sl pos -> [@@ inline_let ]let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@@ inline_let ]let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_repr", "LowParse.Spec.Enum.enum_key", "Prims.eq2", "LowParse.Spec.Enum.enum_key_of_repr", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Low.BitSum.validate_bitsum_cases_t", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum'", "Prims.Mkdtuple2", "FStar.UInt.uint_t", "LowParse.BitFields.__proj__Mkuint_t__item__v", "LowParse.BitFields.get_bitfield", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k))))
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (key_of: (x: enum_repr e -> Tot (y: enum_key e {y == enum_key_of_repr e x}))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: (k: enum_key e -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload))
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitsum_gen
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> key_of: (x: LowParse.Spec.Enum.enum_repr e -> y: LowParse.Spec.Enum.enum_key e {y == LowParse.Spec.Enum.enum_key_of_repr e x}) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> destr_payload: (k: LowParse.Spec.Enum.enum_key e -> LowParse.Low.BitSum.validate_bitsum_cases_t (payload k)) -> LowParse.Low.BitSum.validate_bitsum_cases_t (LowParse.Spec.BitSum.BitSum' key key_size e payload)
{ "end_col": 17, "end_line": 100, "start_col": 2, "start_line": 90 }
FStar.Pervasives.Lemma
val valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos)))) (ensures (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1)))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos) ))) (ensures ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1) )) = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1
val valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos)))) (ensures (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1))) let valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos)))) (ensures (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1))) =
false
null
true
valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.synth_case_t", "LowParse.Spec.Base.parser", "Prims.dtuple2", "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_facts", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BitSum.parse_bitsum'", "LowParse.Spec.BitSum.bitsum'_key_of_t", "LowParse.Low.Base.Spec.contents", "Prims.unit", "LowParse.Spec.BitSum.parse_bitsum_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BitSum.parse_bitsum_kind", "LowParse.Spec.BitSum.parse_bitsum", "Prims.l_and", "LowParse.Low.Base.Spec.valid", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.BitSum.__proj__SynthCase__item__f", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *)) #push-options "--z3rlimit 32" inline_for_extraction let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun u f v x xr #rrel #rel sl pos -> // [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x sl pos else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) (mk_validate_bitsum_cases_t': (* universe-polymorphic mutually recursive functions must be "split off" cf. https://github.com/FStarLang/FStar/issues/1480#issuecomment-623260544 *) (b: bitsum' cl (bitsum'_size - key_size) { b << BitSum' key key_size e payload }) -> Tot (validate_bitsum_cases_t u#r b) ) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in validate_bitsum_cases_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in validate_bitsum_cases_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_validate_bitsum_cases_t' (payload k)) (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q mk_validate_bitsum_cases_t') [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b) = match b with | BitStop _ -> validate_bitsum_cases_bitstop cl | BitField sz rest -> validate_bitsum_cases_bitfield cl bitsum'_size sz rest (mk_validate_bitsum_cases_t' rest) | BitSum' key key_size e payload -> validate_bitsum_cases_bitsum'_intro cl bitsum'_size key key_size e payload (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload [] e (mk_validate_bitsum_cases_t' #tot #t #cl #(bitsum'_size - key_size))) #push-options "--z3rlimit 64" #restart-solver inline_for_extraction let validate_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (vf: (x: bitsum'_key_type b) -> Tot (validator (dsnd (f x)))) (vs: validate_bitsum_cases_t b) : Tot (validator (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl (uint64_to_uint32 pos); parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl (uint64_to_uint32 pos)); valid_facts (parse_bitsum' b p) h sl (uint64_to_uint32 pos) in let pos1 = validate_bitsum' b v r phi sl pos in if is_error pos1 then pos1 else [@inline_let] let _ = synth_bitsum'_injective b; parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (bytes_of_slice_from h sl (uint64_to_uint32 pos)); parse_filter_eq p (filter_bitsum' b) (bytes_of_slice_from h sl (uint64_to_uint32 pos)); valid_facts p h sl (uint64_to_uint32 pos) in let x = r sl (uint64_to_uint32 pos) in [@inline_let] let _ = let y = synth_bitsum' b x in let tg = bitsum'_key_of_t b y in parse_synth_eq (dsnd (f tg)) (synth_case.f y) (bytes_of_slice_from h sl (uint64_to_uint32 pos1)); valid_facts (dsnd (f tg)) h sl (uint64_to_uint32 pos1) in vs (type_of_tag) f vf x sl pos1 #pop-options let valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos) ))) (ensures ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1)
false
false
LowParse.Low.BitSum.fst
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos)))) (ensures (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1)))
[]
LowParse.Low.BitSum.valid_bitsum_intro
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Spec.BitSum.bitsum' cl tot -> tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) -> type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) -> synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag -> p: LowParse.Spec.Base.parser kt t -> f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) -> h: FStar.Monotonic.HyperStack.mem -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos /\ (let tg = LowParse.Low.Base.Spec.contents (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos in let k = LowParse.Spec.BitSum.bitsum'_key_of_t b tg in LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (f k)) h sl (LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos) )) (ensures (let tg = LowParse.Low.Base.Spec.contents (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos in let k = LowParse.Spec.BitSum.bitsum'_key_of_t b tg in let pos1 = LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos in let y = LowParse.Low.Base.Spec.contents (FStar.Pervasives.dsnd (f k)) h sl pos1 in LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.BitSum.parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (SynthCase?.f synth_case tg y) (LowParse.Low.Base.Spec.get_valid_pos (FStar.Pervasives.dsnd (f k)) h sl pos1)))
{ "end_col": 36, "end_line": 349, "start_col": 2, "start_line": 343 }
FStar.Pervasives.Lemma
val valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ (let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1)))))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos )) (ensures ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ ( let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1) )))) = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1; valid_bitsum_intro b tag_of_data type_of_tag synth_case p f h sl pos
val valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ (let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1))))) let valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ (let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1))))) =
false
null
true
valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1; valid_bitsum_intro b tag_of_data type_of_tag synth_case p f h sl pos
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.synth_case_t", "LowParse.Spec.Base.parser", "Prims.dtuple2", "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.BitSum.valid_bitsum_intro", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BitSum.parse_bitsum'", "LowParse.Spec.BitSum.bitsum'_key_of_t", "LowParse.Low.Base.Spec.contents", "LowParse.Spec.BitSum.parse_bitsum_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.BitSum.parse_bitsum_kind", "LowParse.Spec.BitSum.parse_bitsum", "LowParse.Low.Base.Spec.valid", "Prims.squash", "Prims.l_and", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.BitSum.__proj__SynthCase__item__f", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *)) #push-options "--z3rlimit 32" inline_for_extraction let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun u f v x xr #rrel #rel sl pos -> // [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x sl pos else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) (mk_validate_bitsum_cases_t': (* universe-polymorphic mutually recursive functions must be "split off" cf. https://github.com/FStarLang/FStar/issues/1480#issuecomment-623260544 *) (b: bitsum' cl (bitsum'_size - key_size) { b << BitSum' key key_size e payload }) -> Tot (validate_bitsum_cases_t u#r b) ) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in validate_bitsum_cases_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in validate_bitsum_cases_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_validate_bitsum_cases_t' (payload k)) (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q mk_validate_bitsum_cases_t') [@filter_bitsum'_t_attr] noextract let rec mk_validate_bitsum_cases_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (validate_bitsum_cases_t u#r b) (decreases b) = match b with | BitStop _ -> validate_bitsum_cases_bitstop cl | BitField sz rest -> validate_bitsum_cases_bitfield cl bitsum'_size sz rest (mk_validate_bitsum_cases_t' rest) | BitSum' key key_size e payload -> validate_bitsum_cases_bitsum'_intro cl bitsum'_size key key_size e payload (mk_validate_bitsum_cases_bitsum'_t' cl bitsum'_size key key_size e payload [] e (mk_validate_bitsum_cases_t' #tot #t #cl #(bitsum'_size - key_size))) #push-options "--z3rlimit 64" #restart-solver inline_for_extraction let validate_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (vf: (x: bitsum'_key_type b) -> Tot (validator (dsnd (f x)))) (vs: validate_bitsum_cases_t b) : Tot (validator (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl (uint64_to_uint32 pos); parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl (uint64_to_uint32 pos)); valid_facts (parse_bitsum' b p) h sl (uint64_to_uint32 pos) in let pos1 = validate_bitsum' b v r phi sl pos in if is_error pos1 then pos1 else [@inline_let] let _ = synth_bitsum'_injective b; parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (bytes_of_slice_from h sl (uint64_to_uint32 pos)); parse_filter_eq p (filter_bitsum' b) (bytes_of_slice_from h sl (uint64_to_uint32 pos)); valid_facts p h sl (uint64_to_uint32 pos) in let x = r sl (uint64_to_uint32 pos) in [@inline_let] let _ = let y = synth_bitsum' b x in let tg = bitsum'_key_of_t b y in parse_synth_eq (dsnd (f tg)) (synth_case.f y) (bytes_of_slice_from h sl (uint64_to_uint32 pos1)); valid_facts (dsnd (f tg)) h sl (uint64_to_uint32 pos1) in vs (type_of_tag) f vf x sl pos1 #pop-options let valid_bitsum_intro (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in valid (dsnd (f k)) h sl (get_valid_pos (parse_bitsum' b p) h sl pos) ))) (ensures ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1) )) = valid_facts (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos; parse_bitsum_eq b tag_of_data type_of_tag synth_case p f (bytes_of_slice_from h sl pos); valid_facts (parse_bitsum' b p) h sl pos; let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid_facts (dsnd (f k)) h sl pos1 #pop-options let valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (h: HS.mem) (#rrel: _) (#rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos )) (ensures ( valid (parse_bitsum' b p) h sl pos /\ ( let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ ( let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1)
false
false
LowParse.Low.BitSum.fst
{ "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bitsum_elim' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) (h: HS.mem) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos)) (ensures (valid (parse_bitsum' b p) h sl pos /\ (let tg = contents (parse_bitsum' b p) h sl pos in let k = bitsum'_key_of_t b tg in let pos1 = get_valid_pos (parse_bitsum' b p) h sl pos in valid (dsnd (f k)) h sl pos1 /\ (let y = contents (dsnd (f k)) h sl pos1 in valid_content_pos (parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (synth_case.f tg y) (get_valid_pos (dsnd (f k)) h sl pos1)))))
[]
LowParse.Low.BitSum.valid_bitsum_elim'
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Spec.BitSum.bitsum' cl tot -> tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) -> type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) -> synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag -> p: LowParse.Spec.Base.parser kt t -> f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) -> h: FStar.Monotonic.HyperStack.mem -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.BitSum.parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos) (ensures LowParse.Low.Base.Spec.valid (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos /\ (let tg = LowParse.Low.Base.Spec.contents (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos in let k = LowParse.Spec.BitSum.bitsum'_key_of_t b tg in let pos1 = LowParse.Low.Base.Spec.get_valid_pos (LowParse.Spec.BitSum.parse_bitsum' b p) h sl pos in LowParse.Low.Base.Spec.valid (FStar.Pervasives.dsnd (f k)) h sl pos1 /\ (let y = LowParse.Low.Base.Spec.contents (FStar.Pervasives.dsnd (f k)) h sl pos1 in LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.BitSum.parse_bitsum b tag_of_data type_of_tag synth_case p f) h sl pos (SynthCase?.f synth_case tg y) (LowParse.Low.Base.Spec.get_valid_pos (FStar.Pervasives.dsnd (f k)) h sl pos1))))
{ "end_col": 70, "end_line": 390, "start_col": 2, "start_line": 383 }
Prims.Tot
val validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "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 } ]
false
let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun u f v x xr #rrel #rel sl pos -> // [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x sl pos else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos
val validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) =
false
null
false
fun u f v x xr #rrel #rel sl pos -> let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@@ inline_let ]let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@@ inline_let ]let cond = (xr <: t) = yr in [@@ inline_let ]let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)) ) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |)) ) x sl pos else [@@ inline_let ]let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail u f v (x <: t) xr sl pos
{ "checked_file": "LowParse.Low.BitSum.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BitSum.fst.checked", "LowParse.Low.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.BitSum.fst" }
[ "total" ]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.eq2", "FStar.List.Tot.Base.append", "Prims.Cons", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.fst", "LowParse.Spec.Enum.enum_repr_of_key", "Prims.Nil", "LowParse.Low.BitSum.validate_bitsum_cases_t", "LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.validator", "Prims.__proj__Mkdtuple2__item___1", "FStar.Pervasives.dsnd", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.l_not", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "FStar.Pervasives.Native.snd", "LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_lhs", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum'", "Prims.Mkdtuple2", "Prims.bool", "Prims.unit", "FStar.List.Tot.Properties.append_mem", "FStar.List.Tot.Base.map", "FStar.List.Tot.Properties.map_append", "FStar.List.Tot.Properties.append_assoc", "Prims._assert", "Prims.l_iff", "Prims.op_Equality", "LowParse.BitFields.__proj__Mkuint_t__item__bitfield_eq_rhs", "LowParse.Spec.Enum.enum_repr_of_key_append_cons" ]
[]
module LowParse.Low.BitSum include LowParse.Low.Combinators include LowParse.Spec.BitSum module U32 = FStar.UInt32 module HS = FStar.HyperStack #push-options "--z3rlimit 16" inline_for_extraction let validate_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (v: validator p) (r: leaf_reader p) (phi: filter_bitsum'_t b) : Tot (validator (parse_bitsum' b p)) = synth_bitsum'_injective b; validate_synth (validate_filter v r (filter_bitsum' b) (fun x -> phi x)) (synth_bitsum' b) () module HST = FStar.HyperStack.ST inline_for_extraction noextract let validate_bitsum_cases_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type b -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type b) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (validator (dsnd (f (bitsum'_key_of_t b (synth_bitsum' b x))))) inline_for_extraction let validate_bitsum_cases_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (validate_bitsum_cases_t u#r #tot #t #cl #0 (BitStop ())) = fun u f v x #rrel #rel sl pos -> v () sl pos inline_for_extraction let validate_bitsum_cases_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: validate_bitsum_cases_t u#r rest) : Tot (validate_bitsum_cases_t u#r (BitField sz rest)) = fun u f v x #rrel #rel sl pos -> phi (fun x -> u (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> f (coerce (bitsum'_key_type (BitField sz rest)) x)) (fun x -> v (coerce (bitsum'_key_type (BitField sz rest)) x)) x sl pos inline_for_extraction let validate_bitsum_cases_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (destr_payload: ((k: enum_key e) -> Tot (validate_bitsum_cases_t u#r (payload k)))) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x_ #rrel #rel sl pos -> [@inline_let] let r = cl.get_bitfield x_ (bitsum'_size - key_size) bitsum'_size in [@inline_let] let k = key_of r in destr_payload k (fun x -> u (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) (fun x -> v (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, x |))) x_ sl pos module L = FStar.List.Tot inline_for_extraction noextract let validate_bitsum_cases_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (Type u#(r+1)) = (u: (bitsum'_key_type (BitSum' key key_size e payload) -> Tot (Type u#r))) -> (f: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (k: parser_kind & parser k (u x)))) -> (v: ((x: bitsum'_key_type (BitSum' key key_size e payload)) -> Tot (validator (dsnd (f x))))) -> (x: parse_filter_refine (filter_bitsum' (BitSum' key key_size e payload)) { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (validator (dsnd (f (bitsum'_key_of_t (BitSum' key key_size e payload) (synth_bitsum' (BitSum' key key_size e payload) x))))) inline_for_extraction let validate_bitsum_cases_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload [] e) : Tot (validate_bitsum_cases_t u#r (BitSum' key key_size e payload)) = fun u f v x #rrel #rel sl pos -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi u f v x xr sl pos inline_for_extraction let validate_bitsum_cases_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload e []) = (fun u f v x xr #rrel #rel sl pos -> assert False; validator_error_generic (* dummy *)) #push-options "--z3rlimit 32" inline_for_extraction let validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2)
false
false
LowParse.Low.BitSum.fst
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bitsum_cases_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: validate_bitsum_cases_t u#r (payload k)) (destr_tail: validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (validate_bitsum_cases_bitsum'_t u#r cl bitsum'_size key key_size e payload l1 ((k, r) :: l2))
[]
LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_cons
{ "file_name": "src/lowparse/LowParse.Low.BitSum.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> l1: Prims.list (key * LowParse.BitFields.bitfield cl key_size) -> k: key -> r: LowParse.BitFields.bitfield cl key_size -> l2: Prims.list (key * LowParse.BitFields.bitfield cl key_size) { e == l1 @ FStar.Pervasives.Native.Mktuple2 k r :: l2 /\ LowParse.Spec.Enum.list_mem k (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst e) /\ LowParse.Spec.Enum.enum_repr_of_key e k == r /\ e == (l1 @ [k, r]) @ l2 } -> destr_payload: LowParse.Low.BitSum.validate_bitsum_cases_t (payload k) -> destr_tail: LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t cl bitsum'_size key key_size e payload (l1 @ [k, r]) l2 -> LowParse.Low.BitSum.validate_bitsum_cases_bitsum'_t cl bitsum'_size key key_size e payload l1 (FStar.Pervasives.Native.Mktuple2 k r :: l2)
{ "end_col": 41, "end_line": 204, "start_col": 2, "start_line": 181 }
Prims.Tot
val equal (regs1:t) (regs2:t) : prop0
[ { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "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 } ]
false
let equal regs1 regs2 = feq regs1 regs2
val equal (regs1:t) (regs2:t) : prop0 let equal regs1 regs2 =
false
null
false
feq regs1 regs2
{ "checked_file": "Vale.PPC64LE.Regs.fst.checked", "dependencies": [ "Vale.PPC64LE.Machine_s.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.Regs.fst" }
[ "total" ]
[ "Vale.PPC64LE.Regs.t", "FStar.FunctionalExtensionality.feq", "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.Machine_s.nat64", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.PPC64LE.Regs open Vale.PPC64LE.Machine_s open FStar.FunctionalExtensionality
false
true
Vale.PPC64LE.Regs.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val equal (regs1:t) (regs2:t) : prop0
[]
Vale.PPC64LE.Regs.equal
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Regs.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
regs1: Vale.PPC64LE.Regs.t -> regs2: Vale.PPC64LE.Regs.t -> Vale.Def.Prop_s.prop0
{ "end_col": 39, "end_line": 5, "start_col": 24, "start_line": 5 }
Prims.Tot
val linv_ctx (a: LSeq.lseq uint64 0) : Type0
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
val linv_ctx (a: LSeq.lseq uint64 0) : Type0 let linv_ctx (a: LSeq.lseq uint64 0) : Type0 =
false
null
false
True
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Prims.l_True" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val linv_ctx (a: LSeq.lseq uint64 0) : Type0
[]
Hacl.Impl.K256.Qinv.linv_ctx
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Lib.Sequence.lseq Lib.IntTypes.uint64 0 -> Type0
{ "end_col": 50, "end_line": 25, "start_col": 46, "start_line": 25 }
FStar.HyperStack.ST.Stack
val qinv (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == S.qinv (qas_nat h0 f) /\ qe_lt_q h1 out)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv out f = let h0 = ST.get () in SI.qinv_is_qinv_lemma (qas_nat h0 f); qinv_ out f
val qinv (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == S.qinv (qas_nat h0 f) /\ qe_lt_q h1 out) let qinv out f =
true
null
false
let h0 = ST.get () in SI.qinv_is_qinv_lemma (qas_nat h0 f); qinv_ out f
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Hacl.Impl.K256.Qinv.qinv_", "Prims.unit", "Hacl.Spec.K256.Qinv.qinv_is_qinv_lemma", "Hacl.K256.Scalar.qas_nat", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111)) // r9; ..; r15 inline_for_extraction noextract val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv5 tmp x_101 x_111 x_1001 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r9 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r10 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; //tmp = r11 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r12 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; //tmp = r13 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; //tmp = r14 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r15 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111)) // r16; ..;r23 inline_for_extraction noextract val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 9ul; qmul tmp tmp x8; //tmp = r16 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r17 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1011; //tmp = r18 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1101; //tmp = r19 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_11; //tmp = r20 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r21 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_1101; //tmp = r22 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1001; //tmp = r23 let h8 = ST.get () in assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001)) //r24; r25 inline_for_extraction noextract val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp) let qinv7 tmp f x6 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp f; //tmp = r23 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 f)); qsquare_times_in_place tmp 8ul; qmul tmp tmp x6; //tmp = r24 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 8) (qas_nat h0 x6)) inline_for_extraction noextract val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f) (qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv8 tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101 = push_frame (); let x6 = create_qelem () in let x8 = create_qelem () in let x14 = create_qelem () in let h1 = ST.get () in qinv2 x_11 x_1011 x_1101 x6 x8 x14; //x6; x8; x14 let h2 = ST.get () in assert (modifies (loc x6 |+| loc x8 |+| loc x14) h1 h2); qinv3 tmp x14; //x28; x56; r0; r1 let h3 = ST.get () in assert (modifies (loc tmp) h2 h3); qinv4 tmp x_101 x_111 x_1011; //r2; ..; r8 let h4 = ST.get () in assert (modifies (loc tmp) h3 h4); qinv5 tmp x_101 x_111 x_1001 x_1101; //r9; ..; r15 let h5 = ST.get () in assert (modifies (loc tmp) h4 h5); qinv6 tmp x8 x_11 x_1001 x_1011 x_1101; //r16; ..; r23 let h6 = ST.get () in assert (modifies (loc tmp) h5 h6); qinv7 tmp f x6; //r24; r25 let h7 = ST.get () in assert (modifies (loc tmp) h6 h7); pop_frame () inline_for_extraction noextract val qinv_ (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == SI.qinv (qas_nat h0 f) /\ qe_lt_q h1 out) #set-options "--z3rlimit 150" let qinv_ out f = push_frame (); let x_10 = create_qelem () in let x_11 = create_qelem () in let x_101 = create_qelem () in let x_111 = create_qelem () in let x_1001 = create_qelem () in let x_1011 = create_qelem () in let x_1101 = create_qelem () in qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101; qinv8 out f x_11 x_101 x_111 x_1001 x_1011 x_1101; pop_frame () val qinv (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == S.qinv (qas_nat h0 f) /\ qe_lt_q h1 out)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qinv (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == S.qinv (qas_nat h0 f) /\ qe_lt_q h1 out)
[]
Hacl.Impl.K256.Qinv.qinv
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.K256.Scalar.qelem -> f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 505, "start_col": 16, "start_line": 502 }
Prims.Tot
val mk_k256_scalar_concrete_ops:BE.concrete_ops U64 4ul 0ul
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; }
val mk_k256_scalar_concrete_ops:BE.concrete_ops U64 4ul 0ul let mk_k256_scalar_concrete_ops:BE.concrete_ops U64 4ul 0ul =
false
null
false
{ BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod }
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Hacl.Impl.Exponentiation.Definitions.Mkconcrete_ops", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "FStar.Ghost.hide", "Hacl.Impl.Exponentiation.Definitions.to_comm_monoid", "Hacl.Impl.K256.Qinv.mk_to_k256_scalar_comm_monoid", "Hacl.Impl.K256.Qinv.one_mod", "Hacl.Impl.K256.Qinv.mul_mod", "Hacl.Impl.K256.Qinv.sqr_mod" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val mk_k256_scalar_concrete_ops:BE.concrete_ops U64 4ul 0ul
[]
Hacl.Impl.K256.Qinv.mk_k256_scalar_concrete_ops
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.concrete_ops Lib.IntTypes.U64 (FStar.UInt32.uint_to_t 4 <: FStar.UInt32.t) (FStar.UInt32.uint_to_t 0 <: FStar.UInt32.t)
{ "end_col": 20, "end_line": 65, "start_col": 2, "start_line": 62 }
Prims.Tot
val mk_to_k256_scalar_comm_monoid:BE.to_comm_monoid U64 4ul 0ul
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; }
val mk_to_k256_scalar_comm_monoid:BE.to_comm_monoid U64 4ul 0ul let mk_to_k256_scalar_comm_monoid:BE.to_comm_monoid U64 4ul 0ul =
false
null
false
{ BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl }
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Hacl.Impl.Exponentiation.Definitions.Mkto_comm_monoid", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "Spec.K256.PointOps.qelem", "Hacl.Spec.K256.Qinv.nat_mod_comm_monoid", "Hacl.Impl.K256.Qinv.linv_ctx", "Hacl.Impl.K256.Qinv.linv", "Hacl.Impl.K256.Qinv.refl" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val mk_to_k256_scalar_comm_monoid:BE.to_comm_monoid U64 4ul 0ul
[]
Hacl.Impl.K256.Qinv.mk_to_k256_scalar_comm_monoid
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.to_comm_monoid Lib.IntTypes.U64 (FStar.UInt32.uint_to_t 4 <: FStar.UInt32.t) (FStar.UInt32.uint_to_t 0 <: FStar.UInt32.t)
{ "end_col": 17, "end_line": 41, "start_col": 2, "start_line": 37 }
FStar.HyperStack.ST.Stack
val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b
val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) let qsquare_times_in_place out b =
true
null
false
let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Lib.IntTypes.size_t", "Hacl.Impl.Exponentiation.lexp_pow2_in_place", "Lib.IntTypes.U64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.K256.Qinv.mk_k256_scalar_concrete_ops", "Lib.Buffer.null", "Lib.Buffer.MUT", "Lib.IntTypes.uint64", "Prims.unit", "Spec.Exponentiation.exp_pow2_lemma", "Spec.K256.PointOps.qelem", "Hacl.Spec.K256.Qinv.mk_nat_mod_concrete_ops", "Hacl.K256.Scalar.qas_nat", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b))
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b))
[]
Hacl.Impl.K256.Qinv.qsquare_times_in_place
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.K256.Scalar.qelem -> b: Lib.IntTypes.size_t -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 79, "end_line": 79, "start_col": 34, "start_line": 76 }
FStar.HyperStack.ST.Stack
val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv7 tmp f x6 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp f; //tmp = r23 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 f)); qsquare_times_in_place tmp 8ul; qmul tmp tmp x6; //tmp = r24 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 8) (qas_nat h0 x6))
val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp) let qinv7 tmp f x6 =
true
null
false
let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp f; let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 f)); qsquare_times_in_place tmp 8ul; qmul tmp tmp x6; let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 8) (qas_nat h0 x6))
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Impl.K256.Qinv.qsquare_times_in_place", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111)) // r9; ..; r15 inline_for_extraction noextract val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv5 tmp x_101 x_111 x_1001 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r9 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r10 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; //tmp = r11 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r12 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; //tmp = r13 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; //tmp = r14 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r15 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111)) // r16; ..;r23 inline_for_extraction noextract val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 9ul; qmul tmp tmp x8; //tmp = r16 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r17 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1011; //tmp = r18 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1101; //tmp = r19 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_11; //tmp = r20 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r21 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_1101; //tmp = r22 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1001; //tmp = r23 let h8 = ST.get () in assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001)) //r24; r25 inline_for_extraction noextract val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp)
[]
Hacl.Impl.K256.Qinv.qinv7
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
tmp: Hacl.K256.Scalar.qelem -> f: Hacl.K256.Scalar.qelem -> x6: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 89, "end_line": 413, "start_col": 20, "start_line": 403 }
Prims.Tot
val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let mul_mod ctx x y xy = qmul xy x y
val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy =
false
null
false
qmul xy x y
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Hacl.K256.Scalar.qmul", "Prims.unit" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
[]
Hacl.Impl.K256.Qinv.mul_mod
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.lmul_st Lib.IntTypes.U64 4ul 0ul Hacl.Impl.K256.Qinv.mk_to_k256_scalar_comm_monoid
{ "end_col": 36, "end_line": 52, "start_col": 25, "start_line": 52 }
FStar.HyperStack.ST.Stack
val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out
val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) let qsquare_times out a b =
true
null
false
let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Lib.IntTypes.size_t", "Hacl.Impl.Exponentiation.lexp_pow2", "Lib.IntTypes.U64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.K256.Qinv.mk_k256_scalar_concrete_ops", "Lib.Buffer.null", "Lib.Buffer.MUT", "Lib.IntTypes.uint64", "Prims.unit", "Spec.Exponentiation.exp_pow2_lemma", "Spec.K256.PointOps.qelem", "Hacl.Spec.K256.Qinv.mk_nat_mod_concrete_ops", "Hacl.K256.Scalar.qas_nat", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b))
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b))
[]
Hacl.Impl.K256.Qinv.qsquare_times
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.K256.Scalar.qelem -> a: Hacl.K256.Scalar.qelem -> b: Lib.IntTypes.size_t -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 72, "end_line": 93, "start_col": 27, "start_line": 90 }
Prims.Tot
val linv (a: LSeq.lseq uint64 4) : Type0
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q
val linv (a: LSeq.lseq uint64 4) : Type0 let linv (a: LSeq.lseq uint64 4) : Type0 =
false
null
false
SD.bn_v #U64 #4 a < S.q
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.U64", "Spec.K256.PointOps.q" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val linv (a: LSeq.lseq uint64 4) : Type0
[]
Hacl.Impl.K256.Qinv.linv
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Lib.Sequence.lseq Lib.IntTypes.uint64 4 -> Type0
{ "end_col": 25, "end_line": 29, "start_col": 2, "start_line": 29 }
Prims.Tot
val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0)
val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one =
false
null
false
make_u64_4 one (u64 1, u64 0, u64 0, u64 0)
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Hacl.K256.Scalar.make_u64_4", "FStar.Pervasives.Native.Mktuple4", "Lib.IntTypes.uint64", "Lib.IntTypes.u64", "Prims.unit" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
[]
Hacl.Impl.K256.Qinv.one_mod
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.lone_st Lib.IntTypes.U64 4ul 0ul Hacl.Impl.K256.Qinv.mk_to_k256_scalar_comm_monoid
{ "end_col": 65, "end_line": 47, "start_col": 22, "start_line": 47 }
Prims.Tot
val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let sqr_mod ctx x xx = qsqr xx x
val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx =
false
null
false
qsqr xx x
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.__uint_to_t", "Hacl.K256.Scalar.qsqr", "Prims.unit" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
[]
Hacl.Impl.K256.Qinv.sqr_mod
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Exponentiation.Definitions.lsqr_st Lib.IntTypes.U64 4ul 0ul Hacl.Impl.K256.Qinv.mk_to_k256_scalar_comm_monoid
{ "end_col": 32, "end_line": 57, "start_col": 23, "start_line": 57 }
FStar.HyperStack.ST.Stack
val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6))
val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 =
true
null
false
let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6))
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Impl.K256.Qinv.qsquare_times", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14))
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14))
[]
Hacl.Impl.K256.Qinv.qinv2
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x_11: Hacl.K256.Scalar.qelem -> x_1011: Hacl.K256.Scalar.qelem -> x_1101: Hacl.K256.Scalar.qelem -> x6: Hacl.K256.Scalar.qelem -> x8: Hacl.K256.Scalar.qelem -> x14: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 88, "end_line": 193, "start_col": 40, "start_line": 178 }
Prims.GTot
val refl (a: LSeq.lseq uint64 4 {linv a}) : GTot S.qelem
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a
val refl (a: LSeq.lseq uint64 4 {linv a}) : GTot S.qelem let refl (a: LSeq.lseq uint64 4 {linv a}) : GTot S.qelem =
false
null
false
SD.bn_v #U64 #4 a
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[ "sometrivial" ]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Hacl.Impl.K256.Qinv.linv", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.U64", "Spec.K256.PointOps.qelem" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val refl (a: LSeq.lseq uint64 4 {linv a}) : GTot S.qelem
[]
Hacl.Impl.K256.Qinv.refl
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Lib.Sequence.lseq Lib.IntTypes.uint64 4 {Hacl.Impl.K256.Qinv.linv a} -> Prims.GTot Spec.K256.PointOps.qelem
{ "end_col": 19, "end_line": 33, "start_col": 2, "start_line": 33 }
FStar.HyperStack.ST.Stack
val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011))
val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 =
true
null
false
let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011))
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "Hacl.Impl.K256.Qinv.qsquare_times", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101))
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101))
[]
Hacl.Impl.K256.Qinv.qinv1
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: Hacl.K256.Scalar.qelem -> x_10: Hacl.K256.Scalar.qelem -> x_11: Hacl.K256.Scalar.qelem -> x_101: Hacl.K256.Scalar.qelem -> x_111: Hacl.K256.Scalar.qelem -> x_1001: Hacl.K256.Scalar.qelem -> x_1011: Hacl.K256.Scalar.qelem -> x_1101: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 76, "end_line": 157, "start_col": 56, "start_line": 129 }
FStar.HyperStack.ST.Stack
val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame ()
val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 =
true
null
false
push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame ()
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Impl.K256.Qinv.qsquare_times_in_place", "FStar.UInt32.__uint_to_t", "Hacl.Impl.K256.Qinv.qsquare_times", "Hacl.K256.Scalar.create_qelem", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp)
[]
Hacl.Impl.K256.Qinv.qinv3
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
tmp: Hacl.K256.Scalar.qelem -> x14: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 229, "start_col": 2, "start_line": 206 }
FStar.HyperStack.ST.Stack
val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111))
val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 =
true
null
false
let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111))
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Impl.K256.Qinv.qsquare_times_in_place", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp)
[]
Hacl.Impl.K256.Qinv.qinv4
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
tmp: Hacl.K256.Scalar.qelem -> x_101: Hacl.K256.Scalar.qelem -> x_111: Hacl.K256.Scalar.qelem -> x_1011: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 92, "end_line": 279, "start_col": 34, "start_line": 244 }
FStar.HyperStack.ST.Stack
val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv5 tmp x_101 x_111 x_1001 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r9 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r10 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; //tmp = r11 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r12 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; //tmp = r13 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; //tmp = r14 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r15 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111))
val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv5 tmp x_101 x_111 x_1001 x_1101 =
true
null
false
let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111))
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Impl.K256.Qinv.qsquare_times_in_place", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111)) // r9; ..; r15 inline_for_extraction noextract val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
[]
Hacl.Impl.K256.Qinv.qinv5
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
tmp: Hacl.K256.Scalar.qelem -> x_101: Hacl.K256.Scalar.qelem -> x_111: Hacl.K256.Scalar.qelem -> x_1001: Hacl.K256.Scalar.qelem -> x_1101: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 92, "end_line": 331, "start_col": 41, "start_line": 296 }
FStar.HyperStack.ST.Stack
val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 9ul; qmul tmp tmp x8; //tmp = r16 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r17 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1011; //tmp = r18 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1101; //tmp = r19 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_11; //tmp = r20 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r21 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_1101; //tmp = r22 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1001; //tmp = r23 let h8 = ST.get () in assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001))
val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 =
true
null
false
let h0 = ST.get () in qsquare_times_in_place tmp 9ul; qmul tmp tmp x8; let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1011; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1101; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_11; let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_1101; let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1001; let h8 = ST.get () in assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001))
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "Prims._assert", "Prims.eq2", "Prims.nat", "Hacl.K256.Scalar.qas_nat", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Scalar.qmul", "Hacl.Impl.K256.Qinv.qsquare_times_in_place", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111)) // r9; ..; r15 inline_for_extraction noextract val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv5 tmp x_101 x_111 x_1001 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r9 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r10 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; //tmp = r11 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r12 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; //tmp = r13 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; //tmp = r14 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r15 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111)) // r16; ..;r23 inline_for_extraction noextract val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
[]
Hacl.Impl.K256.Qinv.qinv6
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
tmp: Hacl.K256.Scalar.qelem -> x8: Hacl.K256.Scalar.qelem -> x_11: Hacl.K256.Scalar.qelem -> x_1001: Hacl.K256.Scalar.qelem -> x_1011: Hacl.K256.Scalar.qelem -> x_1101: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 93, "end_line": 389, "start_col": 44, "start_line": 349 }
FStar.HyperStack.ST.Stack
val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f) (qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv8 tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101 = push_frame (); let x6 = create_qelem () in let x8 = create_qelem () in let x14 = create_qelem () in let h1 = ST.get () in qinv2 x_11 x_1011 x_1101 x6 x8 x14; //x6; x8; x14 let h2 = ST.get () in assert (modifies (loc x6 |+| loc x8 |+| loc x14) h1 h2); qinv3 tmp x14; //x28; x56; r0; r1 let h3 = ST.get () in assert (modifies (loc tmp) h2 h3); qinv4 tmp x_101 x_111 x_1011; //r2; ..; r8 let h4 = ST.get () in assert (modifies (loc tmp) h3 h4); qinv5 tmp x_101 x_111 x_1001 x_1101; //r9; ..; r15 let h5 = ST.get () in assert (modifies (loc tmp) h4 h5); qinv6 tmp x8 x_11 x_1001 x_1011 x_1101; //r16; ..; r23 let h6 = ST.get () in assert (modifies (loc tmp) h5 h6); qinv7 tmp f x6; //r24; r25 let h7 = ST.get () in assert (modifies (loc tmp) h6 h7); pop_frame ()
val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f) (qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv8 tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101 =
true
null
false
push_frame (); let x6 = create_qelem () in let x8 = create_qelem () in let x14 = create_qelem () in let h1 = ST.get () in qinv2 x_11 x_1011 x_1101 x6 x8 x14; let h2 = ST.get () in assert (modifies (loc x6 |+| loc x8 |+| loc x14) h1 h2); qinv3 tmp x14; let h3 = ST.get () in assert (modifies (loc tmp) h2 h3); qinv4 tmp x_101 x_111 x_1011; let h4 = ST.get () in assert (modifies (loc tmp) h3 h4); qinv5 tmp x_101 x_111 x_1001 x_1101; let h5 = ST.get () in assert (modifies (loc tmp) h4 h5); qinv6 tmp x8 x_11 x_1001 x_1011 x_1101; let h6 = ST.get () in assert (modifies (loc tmp) h5 h6); qinv7 tmp f x6; let h7 = ST.get () in assert (modifies (loc tmp) h6 h7); pop_frame ()
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Prims._assert", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Lib.Buffer.MUT", "Lib.IntTypes.uint64", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.K256.Qinv.qinv7", "Hacl.Impl.K256.Qinv.qinv6", "Hacl.Impl.K256.Qinv.qinv5", "Hacl.Impl.K256.Qinv.qinv4", "Hacl.Impl.K256.Qinv.qinv3", "Lib.Buffer.op_Bar_Plus_Bar", "Hacl.Impl.K256.Qinv.qinv2", "Hacl.K256.Scalar.create_qelem", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111)) // r9; ..; r15 inline_for_extraction noextract val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv5 tmp x_101 x_111 x_1001 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r9 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r10 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; //tmp = r11 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r12 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; //tmp = r13 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; //tmp = r14 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r15 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111)) // r16; ..;r23 inline_for_extraction noextract val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 9ul; qmul tmp tmp x8; //tmp = r16 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r17 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1011; //tmp = r18 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1101; //tmp = r19 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_11; //tmp = r20 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r21 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_1101; //tmp = r22 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1001; //tmp = r23 let h8 = ST.get () in assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001)) //r24; r25 inline_for_extraction noextract val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp) let qinv7 tmp f x6 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp f; //tmp = r23 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 f)); qsquare_times_in_place tmp 8ul; qmul tmp tmp x6; //tmp = r24 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 8) (qas_nat h0 x6)) inline_for_extraction noextract val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f) (qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
false
false
Hacl.Impl.K256.Qinv.fst
{ "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" }
null
val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f) (qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp)
[]
Hacl.Impl.K256.Qinv.qinv8
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
tmp: Hacl.K256.Scalar.qelem -> f: Hacl.K256.Scalar.qelem -> x_11: Hacl.K256.Scalar.qelem -> x_101: Hacl.K256.Scalar.qelem -> x_111: Hacl.K256.Scalar.qelem -> x_1001: Hacl.K256.Scalar.qelem -> x_1011: Hacl.K256.Scalar.qelem -> x_1101: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 464, "start_col": 2, "start_line": 435 }
FStar.HyperStack.ST.Stack
val qinv_ (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == SI.qinv (qas_nat h0 f) /\ qe_lt_q h1 out)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Qinv", "short_module": "SI" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.K256.Scalar", "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.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
false
let qinv_ out f = push_frame (); let x_10 = create_qelem () in let x_11 = create_qelem () in let x_101 = create_qelem () in let x_111 = create_qelem () in let x_1001 = create_qelem () in let x_1011 = create_qelem () in let x_1101 = create_qelem () in qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101; qinv8 out f x_11 x_101 x_111 x_1001 x_1011 x_1101; pop_frame ()
val qinv_ (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == SI.qinv (qas_nat h0 f) /\ qe_lt_q h1 out) let qinv_ out f =
true
null
false
push_frame (); let x_10 = create_qelem () in let x_11 = create_qelem () in let x_101 = create_qelem () in let x_111 = create_qelem () in let x_1001 = create_qelem () in let x_1011 = create_qelem () in let x_1101 = create_qelem () in qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101; qinv8 out f x_11 x_101 x_111 x_1001 x_1011 x_1101; pop_frame ()
{ "checked_file": "Hacl.Impl.K256.Qinv.fst.checked", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Qinv.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.K256.Scalar.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.K256.Qinv.fst" }
[]
[ "Hacl.K256.Scalar.qelem", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.K256.Qinv.qinv8", "Hacl.Impl.K256.Qinv.qinv1", "Hacl.K256.Scalar.create_qelem", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.K256.Qinv open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.K256.Scalar module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Spec.K256 module SI = Hacl.Spec.K256.Qinv module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module SD = Hacl.Spec.Bignum.Definitions #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True unfold let linv (a:LSeq.lseq uint64 4) : Type0 = SD.bn_v #U64 #4 a < S.q unfold let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem = SD.bn_v #U64 #4 a inline_for_extraction noextract let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = { BE.a_spec = S.qelem; BE.comm_monoid = SI.nat_mod_comm_monoid; BE.linv_ctx = linv_ctx; BE.linv = linv; BE.refl = refl; } inline_for_extraction noextract val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0) inline_for_extraction noextract val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let mul_mod ctx x y xy = qmul xy x y inline_for_extraction noextract val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid let sqr_mod ctx x xx = qsqr xx x inline_for_extraction noextract let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = { BE.to = mk_to_k256_scalar_comm_monoid; BE.lone = one_mod; BE.lmul = mul_mod; BE.lsqr = sqr_mod; } val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ qe_lt_q h out) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b)) [@CInline] let qsquare_times_in_place out b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b); BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b val qsquare_times (out a:qelem) (b:size_t) : Stack unit (requires fun h -> live h out /\ live h a /\ disjoint out a /\ qe_lt_q h a) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\ qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b)) [@CInline] let qsquare_times out a b = let h0 = ST.get () in SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b); BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out inline_for_extraction noextract val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit (requires fun h -> live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\ disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\ disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\ disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\ disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\ disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\ disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\ disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\ disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\ disjoint x_1011 x_1101 /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+| loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\ (let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in let _x_11 = S.qmul _x_10 (qas_nat h0 f) in let _x_101 = S.qmul _x_10 _x_11 in let _x_111 = S.qmul _x_10 _x_101 in let _x_1001 = S.qmul _x_10 _x_111 in let _x_1011 = S.qmul _x_10 _x_1001 in let _x_1101 = S.qmul _x_10 _x_1011 in qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\ qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\ qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\ qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\ qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\ qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\ qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101)) let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times x_10 f 1ul; let h1 = ST.get () in assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1); qmul x_11 x_10 f; let h2 = ST.get () in assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f)); qmul x_101 x_10 x_11; let h3 = ST.get () in assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11)); qmul x_111 x_10 x_101; let h4 = ST.get () in assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101)); qmul x_1001 x_10 x_111; let h5 = ST.get () in assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111)); qmul x_1011 x_10 x_1001; let h6 = ST.get () in assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001)); qmul x_1101 x_10 x_1011; let h7 = ST.get () in assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011)) inline_for_extraction noextract val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit (requires fun h -> live h x_11 /\ live h x_1011 /\ live h x_1101 /\ live h x6 /\ live h x8 /\ live h x14 /\ disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\ disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\ disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\ disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\ (let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\ qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\ qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14)) let qinv2 x_11 x_1011 x_1101 x6 x8 x14 = let h0 = ST.get () in qsquare_times x6 x_1101 2ul; qmul x6 x6 x_1011; let h1 = ST.get () in assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011)); qsquare_times x8 x6 2ul; qmul x8 x8 x_11; let h2 = ST.get () in assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11)); qsquare_times x14 x8 6ul; qmul x14 x14 x6; let h3 = ST.get () in assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6)) inline_for_extraction noextract val qinv3 (tmp x14: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x14 /\ disjoint tmp x14 /\ qe_lt_q h x14) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\ qe_lt_q h1 tmp) let qinv3 tmp x14 = push_frame (); let x56 = create_qelem () in let h0 = ST.get () in qsquare_times tmp x14 14ul; qmul tmp tmp x14; //tmp = x28 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14)); qsquare_times x56 tmp 28ul; qmul x56 x56 tmp; let h2 = ST.get () in assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp)); qsquare_times tmp x56 56ul; //tmp = r0 qmul tmp tmp x56; let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56)); qsquare_times_in_place tmp 14ul; //tmp = r1 qmul tmp tmp x14; let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14)); pop_frame () //r2; .. ;r8 inline_for_extraction noextract val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\ qe_lt_q h1 tmp) let qinv4 tmp x_101 x_111 x_1011 = let h0 = ST.get () in qsquare_times_in_place tmp 3ul; qmul tmp tmp x_101; //tmp = r2 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r3 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r4 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1011; //tmp = r5 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1011; //tmp = r6 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r7 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_111; //tmp = r8 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111)) // r9; ..; r15 inline_for_extraction noextract val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv5 tmp x_101 x_111 x_1001 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r9 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_101; //tmp = r10 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101)); qsquare_times_in_place tmp 3ul; qmul tmp tmp x_111; //tmp = r11 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r12 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_101; //tmp = r13 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_111; //tmp = r14 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_111; //tmp = r15 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111)) // r16; ..;r23 inline_for_extraction noextract val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h x8 /\ live h x_11 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp) (qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 = let h0 = ST.get () in qsquare_times_in_place tmp 9ul; qmul tmp tmp x8; //tmp = r16 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_1001; //tmp = r17 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1011; //tmp = r18 let h3 = ST.get () in assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1101; //tmp = r19 let h4 = ST.get () in assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 5ul; qmul tmp tmp x_11; //tmp = r20 let h5 = ST.get () in assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11)); qsquare_times_in_place tmp 6ul; qmul tmp tmp x_1101; //tmp = r21 let h6 = ST.get () in assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 10ul; qmul tmp tmp x_1101; //tmp = r22 let h7 = ST.get () in assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101)); qsquare_times_in_place tmp 4ul; qmul tmp tmp x_1001; //tmp = r23 let h8 = ST.get () in assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001)) //r24; r25 inline_for_extraction noextract val qinv7 (tmp f x6: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x6 /\ disjoint tmp f /\ disjoint tmp x6 /\ qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\ qe_lt_q h1 tmp) let qinv7 tmp f x6 = let h0 = ST.get () in qsquare_times_in_place tmp 6ul; qmul tmp tmp f; //tmp = r23 let h1 = ST.get () in assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 f)); qsquare_times_in_place tmp 8ul; qmul tmp tmp x6; //tmp = r24 let h2 = ST.get () in assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 8) (qas_nat h0 x6)) inline_for_extraction noextract val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit (requires fun h -> live h tmp /\ live h f /\ live h x_11 /\ live h x_101 /\ live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\ disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\ disjoint tmp x_1101 /\ qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f) (qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\ qe_lt_q h1 tmp) let qinv8 tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101 = push_frame (); let x6 = create_qelem () in let x8 = create_qelem () in let x14 = create_qelem () in let h1 = ST.get () in qinv2 x_11 x_1011 x_1101 x6 x8 x14; //x6; x8; x14 let h2 = ST.get () in assert (modifies (loc x6 |+| loc x8 |+| loc x14) h1 h2); qinv3 tmp x14; //x28; x56; r0; r1 let h3 = ST.get () in assert (modifies (loc tmp) h2 h3); qinv4 tmp x_101 x_111 x_1011; //r2; ..; r8 let h4 = ST.get () in assert (modifies (loc tmp) h3 h4); qinv5 tmp x_101 x_111 x_1001 x_1101; //r9; ..; r15 let h5 = ST.get () in assert (modifies (loc tmp) h4 h5); qinv6 tmp x8 x_11 x_1001 x_1011 x_1101; //r16; ..; r23 let h6 = ST.get () in assert (modifies (loc tmp) h5 h6); qinv7 tmp f x6; //r24; r25 let h7 = ST.get () in assert (modifies (loc tmp) h6 h7); pop_frame () inline_for_extraction noextract val qinv_ (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == SI.qinv (qas_nat h0 f) /\ qe_lt_q h1 out) #set-options "--z3rlimit 150"
false
false
Hacl.Impl.K256.Qinv.fst
{ "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": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qinv_ (out f: qelem) : Stack unit (requires fun h -> live h out /\ live h f /\ disjoint out f /\ qe_lt_q h f) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qas_nat h1 out == SI.qinv (qas_nat h0 f) /\ qe_lt_q h1 out)
[]
Hacl.Impl.K256.Qinv.qinv_
{ "file_name": "code/k256/Hacl.Impl.K256.Qinv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.K256.Scalar.qelem -> f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 490, "start_col": 2, "start_line": 479 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len}
let bn_get_top_index_t (len: size_nat) (i: nat{i <= len}) =
false
null
false
x: nat{x < len}
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Lib.IntTypes.size_nat", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); ()
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_top_index_t : len: Lib.IntTypes.size_nat -> i: Prims.nat{i <= len} -> Type0
[]
Hacl.Spec.Bignum.Lib.bn_get_top_index_t
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Lib.IntTypes.size_nat -> i: Prims.nat{i <= len} -> Type0
{ "end_col": 72, "end_line": 312, "start_col": 58, "start_line": 312 }
Prims.Tot
val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2)
val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 =
false
null
false
let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.LoopCombinators.repeati", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Lib.cswap2_f", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len)
[]
Hacl.Spec.Bignum.Lib.cswap2
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
bit: Hacl.Spec.Bignum.Definitions.limb t -> b1: Hacl.Spec.Bignum.Definitions.lbignum t len -> b2: Hacl.Spec.Bignum.Definitions.lbignum t len -> Hacl.Spec.Bignum.Definitions.lbignum t len * Hacl.Spec.Bignum.Definitions.lbignum t len
{ "end_col": 52, "end_line": 278, "start_col": 30, "start_line": 276 }
Prims.Tot
val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1
val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i =
false
null
false
(a >>. size i) &. uint #t 1
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.size", "Lib.IntTypes.uint" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum ///
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t
[]
Hacl.Spec.Bignum.Lib.limb_get_ith_bit
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i < Lib.IntTypes.bits t} -> Hacl.Spec.Bignum.Definitions.limb t
{ "end_col": 57, "end_line": 22, "start_col": 30, "start_line": 22 }
Prims.Tot
val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len}
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0
val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b =
false
null
false
Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.LoopCombinators.repeat_gen", "Hacl.Spec.Bignum.Lib.bn_get_top_index_t", "Hacl.Spec.Bignum.Lib.bn_get_top_index_f", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThan" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len}
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len}
[]
Hacl.Spec.Bignum.Lib.bn_get_top_index
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> res: Lib.IntTypes.size_nat{res < len}
{ "end_col": 80, "end_line": 328, "start_col": 2, "start_line": 328 }
Prims.Tot
val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_mod_pow2 #t #aLen a i = sub a 0 i
val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i =
false
null
false
sub a 0 i
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.sub", "Hacl.Spec.Bignum.Definitions.limb" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i
[]
Hacl.Spec.Bignum.Lib.bn_mod_pow2
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.nat{i <= aLen} -> Hacl.Spec.Bignum.Definitions.lbignum t i
{ "end_col": 40, "end_line": 205, "start_col": 31, "start_line": 205 }
Prims.Tot
val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_div_pow2 #t #len b i = slice b i len
val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i =
false
null
false
slice b i len
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Subtraction" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i)
[]
Hacl.Spec.Bignum.Lib.bn_div_pow2
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i <= len} -> Hacl.Spec.Bignum.Definitions.lbignum t (len - i)
{ "end_col": 15, "end_line": 185, "start_col": 2, "start_line": 185 }
FStar.Pervasives.Lemma
val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c)
val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d =
false
null
true
Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Prims.nat", "FStar.Math.Lemmas.small_division_lemma_1", "Prims.pow2", "Prims.unit", "Prims._assert", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Addition", "Prims.op_Division", "FStar.Math.Lemmas.lemma_div_plus", "FStar.Mul.op_Star", "FStar.Math.Lemmas.lemma_div_lt_nat" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d)
[]
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma_aux
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Prims.nat -> b: Prims.nat -> c: Prims.nat -> d: Prims.nat -> FStar.Pervasives.Lemma (requires a + b * Prims.pow2 c < Prims.pow2 (c + d) /\ a < Prims.pow2 c) (ensures b < Prims.pow2 d)
{ "end_col": 47, "end_line": 106, "start_col": 2, "start_line": 102 }
Prims.Tot
val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2)
val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) =
false
null
false
let dummy = mask &. (p1.[ i ] ^. p2.[ i ]) in let p1 = p1.[ i ] <- p1.[ i ] ^. dummy in let p2 = p2.[ i ] <- p2.[ i ] ^. dummy in (p1, p2)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Lib.IntTypes.logxor", "Lib.IntTypes.SEC", "Lib.Sequence.index", "Prims.l_Forall", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Prims.op_disEquality", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "Lib.IntTypes.op_Hat_Dot", "Lib.Sequence.op_String_Access", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len)
[]
Hacl.Spec.Bignum.Lib.cswap2_f
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mask: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i < len} -> _: (Hacl.Spec.Bignum.Definitions.lbignum t len * Hacl.Spec.Bignum.Definitions.lbignum t len) -> Hacl.Spec.Bignum.Definitions.lbignum t len * Hacl.Spec.Bignum.Definitions.lbignum t len
{ "end_col": 10, "end_line": 265, "start_col": 38, "start_line": 261 }
Prims.Tot
val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv
val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv =
false
null
false
let mask = eq_mask b.[ i ] (zeros t SEC) in if v mask = 0 then i else priv
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Bignum.Lib.bn_get_top_index_t", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.bool", "Prims.op_Addition", "Lib.IntTypes.int_t", "Lib.IntTypes.eq_mask", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.zeros" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1)
[]
Hacl.Spec.Bignum.Lib.bn_get_top_index_f
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Prims.nat{i < len} -> priv: Hacl.Spec.Bignum.Lib.bn_get_top_index_t len i -> Hacl.Spec.Bignum.Lib.bn_get_top_index_t len (i + 1)
{ "end_col": 32, "end_line": 324, "start_col": 41, "start_line": 322 }
FStar.Pervasives.Lemma
val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2)
val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i =
false
null
true
let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.op_Modulus", "Prims.op_Division", "Prims.pow2", "Prims.unit", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.uint", "Lib.IntTypes.mod_mask_lemma", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.size" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2)
[]
Hacl.Spec.Bignum.Lib.limb_get_ith_bit_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i < Lib.IntTypes.bits t} -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v (Hacl.Spec.Bignum.Lib.limb_get_ith_bit a i) == Lib.IntTypes.v a / Prims.pow2 i % 2)
{ "end_col": 37, "end_line": 32, "start_col": 35, "start_line": 27 }
Prims.Tot
val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len}
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b
val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b =
false
null
false
bits t * bn_get_top_index b
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Lib.bn_get_top_index", "Lib.IntTypes.size_nat", "Prims.op_LessThan", "Prims.op_Division" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len}
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len}
[]
Hacl.Spec.Bignum.Lib.bn_low_bound_bits
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> res: Lib.IntTypes.size_nat{res / Lib.IntTypes.bits t < len}
{ "end_col": 29, "end_line": 379, "start_col": 2, "start_line": 379 }
Prims.Tot
val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j
val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind =
false
null
false
let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[ i ] j
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Lib.limb_get_ith_bit", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.int", "Prims.op_Modulus" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t
[]
Hacl.Spec.Bignum.Lib.bn_get_ith_bit
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len} -> Hacl.Spec.Bignum.Definitions.limb t
{ "end_col": 30, "end_line": 38, "start_col": 38, "start_line": 35 }
FStar.Pervasives.Lemma
val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1
val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 =
false
null
true
let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.IntTypes.logxor_lemma", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Hat_Dot", "Prims.unit", "Prims._assert", "Prims.eq2", "Lib.IntTypes.range_t", "Prims.op_Equality", "Prims.int", "Prims.bool", "Lib.IntTypes.uint", "Prims.l_imp", "Lib.IntTypes.logand_lemma", "Lib.IntTypes.op_Amp_Dot", "Prims.op_Subtraction", "Prims.pow2", "Lib.IntTypes.bits", "Lib.IntTypes.op_Subtraction_Dot" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2)
[]
Hacl.Spec.Bignum.Lib.lemma_cswap2_step
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
bit: Hacl.Spec.Bignum.Definitions.limb t {Lib.IntTypes.v bit <= 1} -> p1: Hacl.Spec.Bignum.Definitions.limb t -> p2: Hacl.Spec.Bignum.Definitions.limb t -> FStar.Pervasives.Lemma (ensures (let mask = Lib.IntTypes.uint 0 -. bit in let dummy = mask &. p1 ^. p2 in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in (match Lib.IntTypes.v bit = 1 with | true -> p1' == p2 /\ p2' == p1 | _ -> p1' == p1 /\ p2' == p2) <: Type0))
{ "end_col": 20, "end_line": 250, "start_col": 36, "start_line": 238 }
Prims.Tot
val bn_get_bits: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> limb t
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_bits #t #nLen n ind l = let mask_l = (uint #t #SEC 1 <<. size l) -. uint #t 1 in bn_get_bits_limb n ind &. mask_l
val bn_get_bits: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> limb t let bn_get_bits #t #nLen n ind l =
false
null
false
let mask_l = (uint #t #SEC 1 <<. size l) -. uint #t 1 in bn_get_bits_limb n ind &. mask_l
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Prims.op_Division", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Lib.bn_get_bits_limb", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.uint", "Lib.IntTypes.size", "Hacl.Spec.Bignum.Definitions.limb" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b) let bn_low_bound_bits_lemma #t #len b = let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b) val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t let bn_get_bits_limb #t #nLen n ind = let i = ind / bits t in let j = ind % bits t in let p1 = n.[i] >>. size j in let p2 = if i + 1 < nLen && 0 < j then p1 |. (n.[i + 1] <<. (size (bits t - j))) else p1 in p2 val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1) let bn_get_bits_limb_aux_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in calc (==) { bn_v n / pow2 ind % pow2 pbits; (==) { Math.Lemmas.euclidean_division_definition res (pow2 (pbits - j)) } res / pow2 (pbits - j) * pow2 (pbits - j) + res % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } res / pow2 (pbits - j) * pow2 (pbits - j) + bn_v n / pow2 ind % pow2 (pbits - j); (==) { bn_get_ith_bit_aux_lemma n ind } res / pow2 (pbits - j) * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } bn_v n / pow2 ind / pow2 (pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.division_multiplication_lemma (bn_v n) (pow2 ind) (pow2 (pbits - j)) } bn_v n / (pow2 ind * pow2 (pbits - j)) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_plus ind (pbits - j) } bn_v n / pow2 (ind + pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.euclidean_division_definition ind pbits } bn_v n / pow2 (i * pbits + pbits) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (bn_v n / pow2 (i * pbits + pbits)) pbits (pbits - j) } bn_v n / pow2 (i * pbits + pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.distributivity_add_left i 1 pbits } bn_v n / pow2 ((i + 1) * pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.lemma_mod_mul_distr_l (bn_v n / pow2 ((i + 1) * pbits)) (pow2 (pbits - j)) (pow2 pbits) } bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1; } val bn_get_bits_limb_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma (v (bn_get_bits_limb n ind) == bn_v n / pow2 ind % pow2 (bits t)) let bn_get_bits_limb_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in bn_get_ith_bit_aux_lemma n ind; assert (v p1 == bn_v n / pow2 ind % pow2 (pbits - j)); if j = 0 then () else begin bn_get_bits_limb_aux_lemma n ind; if i + 1 < nLen then begin let p2 = n.[i + 1] <<. (size (pbits - j)) in calc (==) { v p2 % pow2 (pbits - j); (==) { } v n.[i + 1] * pow2 (pbits - j) % pow2 pbits % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (v n.[i + 1] * pow2 (pbits - j)) (pbits - j) pbits } v n.[i + 1] * pow2 (pbits - j) % pow2 (pbits - j); (==) { Math.Lemmas.multiple_modulo_lemma (v n.[i + 1]) (pow2 (pbits - j)) } 0; }; let p3 = p1 |. p2 in logor_disjoint p1 p2 (pbits - j); assert (v p3 == v p1 + v p2); bn_eval_index n (i + 1); assert (res == v p1 + v p2); assert (ind / bits t + 1 < nLen && 0 < ind % bits t) end else begin bn_eval_bound n nLen; assert (bn_v n < pow2 (nLen * pbits)); Math.Lemmas.lemma_div_lt_nat (bn_v n) (nLen * pbits) ((i + 1) * pbits); Math.Lemmas.pow2_minus (nLen * pbits) ((i + 1) * pbits); assert (bn_v n / pow2 ((i + 1) * pbits) < pow2 0); assert_norm (pow2 0 = 1); assert (res == v p1) end end val bn_get_bits: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> limb t
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_bits: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> limb t
[]
Hacl.Spec.Bignum.Lib.bn_get_bits
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen -> i: Lib.IntTypes.size_nat -> l: Lib.IntTypes.size_nat{l < Lib.IntTypes.bits t /\ i / Lib.IntTypes.bits t < nLen} -> Hacl.Spec.Bignum.Definitions.limb t
{ "end_col": 34, "end_line": 512, "start_col": 34, "start_line": 510 }
Prims.Tot
val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_bits_limb #t #nLen n ind = let i = ind / bits t in let j = ind % bits t in let p1 = n.[i] >>. size j in let p2 = if i + 1 < nLen && 0 < j then p1 |. (n.[i + 1] <<. (size (bits t - j))) else p1 in p2
val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t let bn_get_bits_limb #t #nLen n ind =
false
null
false
let i = ind / bits t in let j = ind % bits t in let p1 = n.[ i ] >>. size j in let p2 = if i + 1 < nLen && 0 < j then p1 |. (n.[ i + 1 ] <<. (size (bits t - j))) else p1 in p2
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_AmpAmp", "Prims.op_Addition", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Less_Less_Dot", "Lib.Sequence.op_String_Access", "Lib.IntTypes.size", "Prims.op_Subtraction", "Prims.bool", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Greater_Greater_Dot", "Prims.int", "Prims.op_Modulus" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b) let bn_low_bound_bits_lemma #t #len b = let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b) val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t
[]
Hacl.Spec.Bignum.Lib.bn_get_bits_limb
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen -> ind: Lib.IntTypes.size_nat{ind / Lib.IntTypes.bits t < nLen} -> Hacl.Spec.Bignum.Definitions.limb t
{ "end_col": 4, "end_line": 409, "start_col": 37, "start_line": 404 }
Prims.Tot
val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp
val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind =
false
null
false
let i = ind / bits t in let j = ind % bits t in let inp = input.[ i ] <- input.[ i ] |. (uint #t 1 <<. size j) in inp
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "total" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Lib.IntTypes.logor", "Lib.IntTypes.SEC", "Lib.Sequence.index", "Lib.IntTypes.shift_left", "Lib.IntTypes.mk_int", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.l_Forall", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Prims.op_disEquality", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "Lib.IntTypes.op_Bar_Dot", "Lib.Sequence.op_String_Access", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.uint", "Lib.IntTypes.size", "Prims.int", "Prims.op_Modulus" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len
[]
Hacl.Spec.Bignum.Lib.bn_set_ith_bit
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len} -> Hacl.Spec.Bignum.Definitions.lbignum t len
{ "end_col": 5, "end_line": 94, "start_col": 38, "start_line": 90 }
FStar.Pervasives.Lemma
val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_low_bound_bits_lemma #t #len b = let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b)
val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b) let bn_low_bound_bits_lemma #t #len b =
false
null
true
let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_Equality", "Prims.int", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.pow2", "Prims.bool", "FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_1", "Hacl.Spec.Bignum.Lib.bn_low_bound_bits", "Prims.unit", "Prims._assert", "Prims.op_LessThanOrEqual", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Lib.bn_get_top_index_eval_lemma", "Hacl.Spec.Bignum.Lib.bn_get_top_index_lemma", "Prims.nat", "Prims.op_Subtraction", "Prims.op_LessThan", "Hacl.Spec.Bignum.Lib.bn_get_top_index" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b)
[]
Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> FStar.Pervasives.Lemma (requires 1 < Hacl.Spec.Bignum.Definitions.bn_v b /\ Lib.IntTypes.bits t * len <= Lib.IntTypes.max_size_t /\ Hacl.Spec.Bignum.Definitions.bn_v b % 2 = 1) (ensures Prims.pow2 (Hacl.Spec.Bignum.Lib.bn_low_bound_bits b) < Hacl.Spec.Bignum.Definitions.bn_v b)
{ "end_col": 76, "end_line": 394, "start_col": 39, "start_line": 386 }
FStar.Pervasives.Lemma
val bn_get_bits_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> Lemma (v (bn_get_bits n i l) == bn_v n / pow2 i % pow2 l)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_bits_lemma #t #nLen n ind l = let tmp = bn_get_bits_limb n ind in let mask_l = (uint #t #SEC 1 <<. size l) -. uint #t 1 in let tmp1 = tmp &. mask_l in Math.Lemmas.pow2_lt_compat (bits t) l; mod_mask_lemma tmp (size l); assert (v (mod_mask #t #SEC (size l)) == v mask_l); assert (v tmp1 == v tmp % pow2 l); bn_get_bits_limb_lemma #t #nLen n ind; assert (v tmp1 == bn_v n / pow2 ind % pow2 (bits t) % pow2 l); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) l (bits t); assert (v tmp1 == bn_v n / pow2 ind % pow2 l)
val bn_get_bits_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> Lemma (v (bn_get_bits n i l) == bn_v n / pow2 i % pow2 l) let bn_get_bits_lemma #t #nLen n ind l =
false
null
true
let tmp = bn_get_bits_limb n ind in let mask_l = (uint #t #SEC 1 <<. size l) -. uint #t 1 in let tmp1 = tmp &. mask_l in Math.Lemmas.pow2_lt_compat (bits t) l; mod_mask_lemma tmp (size l); assert (v (mod_mask #t #SEC (size l)) == v mask_l); assert (v tmp1 == v tmp % pow2 l); bn_get_bits_limb_lemma #t #nLen n ind; assert (v tmp1 == bn_v n / pow2 ind % pow2 (bits t) % pow2 l); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) l (bits t); assert (v tmp1 == bn_v n / pow2 ind % pow2 l)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Prims.op_Division", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1", "Hacl.Spec.Bignum.Lib.bn_get_bits_limb_lemma", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "Lib.IntTypes.size", "Lib.IntTypes.mod_mask_lemma", "FStar.Math.Lemmas.pow2_lt_compat", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.uint", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Lib.bn_get_bits_limb" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b) let bn_low_bound_bits_lemma #t #len b = let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b) val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t let bn_get_bits_limb #t #nLen n ind = let i = ind / bits t in let j = ind % bits t in let p1 = n.[i] >>. size j in let p2 = if i + 1 < nLen && 0 < j then p1 |. (n.[i + 1] <<. (size (bits t - j))) else p1 in p2 val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1) let bn_get_bits_limb_aux_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in calc (==) { bn_v n / pow2 ind % pow2 pbits; (==) { Math.Lemmas.euclidean_division_definition res (pow2 (pbits - j)) } res / pow2 (pbits - j) * pow2 (pbits - j) + res % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } res / pow2 (pbits - j) * pow2 (pbits - j) + bn_v n / pow2 ind % pow2 (pbits - j); (==) { bn_get_ith_bit_aux_lemma n ind } res / pow2 (pbits - j) * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } bn_v n / pow2 ind / pow2 (pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.division_multiplication_lemma (bn_v n) (pow2 ind) (pow2 (pbits - j)) } bn_v n / (pow2 ind * pow2 (pbits - j)) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_plus ind (pbits - j) } bn_v n / pow2 (ind + pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.euclidean_division_definition ind pbits } bn_v n / pow2 (i * pbits + pbits) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (bn_v n / pow2 (i * pbits + pbits)) pbits (pbits - j) } bn_v n / pow2 (i * pbits + pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.distributivity_add_left i 1 pbits } bn_v n / pow2 ((i + 1) * pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.lemma_mod_mul_distr_l (bn_v n / pow2 ((i + 1) * pbits)) (pow2 (pbits - j)) (pow2 pbits) } bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1; } val bn_get_bits_limb_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma (v (bn_get_bits_limb n ind) == bn_v n / pow2 ind % pow2 (bits t)) let bn_get_bits_limb_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in bn_get_ith_bit_aux_lemma n ind; assert (v p1 == bn_v n / pow2 ind % pow2 (pbits - j)); if j = 0 then () else begin bn_get_bits_limb_aux_lemma n ind; if i + 1 < nLen then begin let p2 = n.[i + 1] <<. (size (pbits - j)) in calc (==) { v p2 % pow2 (pbits - j); (==) { } v n.[i + 1] * pow2 (pbits - j) % pow2 pbits % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (v n.[i + 1] * pow2 (pbits - j)) (pbits - j) pbits } v n.[i + 1] * pow2 (pbits - j) % pow2 (pbits - j); (==) { Math.Lemmas.multiple_modulo_lemma (v n.[i + 1]) (pow2 (pbits - j)) } 0; }; let p3 = p1 |. p2 in logor_disjoint p1 p2 (pbits - j); assert (v p3 == v p1 + v p2); bn_eval_index n (i + 1); assert (res == v p1 + v p2); assert (ind / bits t + 1 < nLen && 0 < ind % bits t) end else begin bn_eval_bound n nLen; assert (bn_v n < pow2 (nLen * pbits)); Math.Lemmas.lemma_div_lt_nat (bn_v n) (nLen * pbits) ((i + 1) * pbits); Math.Lemmas.pow2_minus (nLen * pbits) ((i + 1) * pbits); assert (bn_v n / pow2 ((i + 1) * pbits) < pow2 0); assert_norm (pow2 0 = 1); assert (res == v p1) end end val bn_get_bits: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> limb t let bn_get_bits #t #nLen n ind l = let mask_l = (uint #t #SEC 1 <<. size l) -. uint #t 1 in bn_get_bits_limb n ind &. mask_l val bn_get_bits_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> Lemma (v (bn_get_bits n i l) == bn_v n / pow2 i % pow2 l)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_bits_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> i:size_nat -> l:size_nat{l < bits t /\ i / bits t < nLen} -> Lemma (v (bn_get_bits n i l) == bn_v n / pow2 i % pow2 l)
[]
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen -> i: Lib.IntTypes.size_nat -> l: Lib.IntTypes.size_nat{l < Lib.IntTypes.bits t /\ i / Lib.IntTypes.bits t < nLen} -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v (Hacl.Spec.Bignum.Lib.bn_get_bits n i l) == Hacl.Spec.Bignum.Definitions.bn_v n / Prims.pow2 i % Prims.pow2 l)
{ "end_col": 47, "end_line": 534, "start_col": 40, "start_line": 523 }
FStar.Pervasives.Lemma
val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2)
val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind =
false
null
true
let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[ i ] j in limb_get_ith_bit_lemma b.[ i ] j; calc ( == ) { v b.[ i ] / pow2 j % 2; ( == ) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; ( == ) { (assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j)) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "Prims.unit", "FStar.Calc.calc_finish", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Lib.bn_get_ith_bit_aux_lemma", "Prims.squash", "FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Hacl.Spec.Bignum.Lib.limb_get_ith_bit_lemma", "Hacl.Spec.Bignum.Lib.limb_get_ith_bit" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2))
[]
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len} -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v (Hacl.Spec.Bignum.Lib.bn_get_ith_bit b i) == Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 i % 2)
{ "end_col": 41, "end_line": 86, "start_col": 40, "start_line": 71 }
FStar.Pervasives.Lemma
val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); }
val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i =
false
null
true
let pbits = bits t in calc ( == ) { bn_v a % pow2 (pbits * i); ( == ) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); ( == ) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); ( == ) { (bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i))) } bn_v (slice a 0 i); }
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "FStar.Math.Lemmas.modulo_addition_lemma", "FStar.Math.Lemmas.small_mod", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} ->
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i))
[]
Hacl.Spec.Bignum.Lib.bn_mod_pow2_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.nat{i <= aLen} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Lib.bn_mod_pow2 a i) == Hacl.Spec.Bignum.Definitions.bn_v a % Prims.pow2 (Lib.IntTypes.bits t * i))
{ "end_col": 5, "end_line": 219, "start_col": 36, "start_line": 209 }
FStar.Pervasives.Lemma
val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind])
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind])
val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind =
false
null
true
let pbits = bits t in assert (forall (k: nat{ind < k /\ k < len}). v b.[ k ] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ ind ])
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Addition", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval1", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Hacl.Spec.Bignum.Definitions.bn_eval_zeroes", "Lib.Sequence.eq_intro", "Lib.Sequence.create", "Lib.IntTypes.uint", "Prims.l_Forall", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Equality", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind])
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind])
[]
Hacl.Spec.Bignum.Lib.bn_get_top_index_eval_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> ind: Prims.nat -> FStar.Pervasives.Lemma (requires ind < len /\ (ind > 0 ==> Lib.IntTypes.v b.[ ind ] <> 0) /\ (forall (k: Prims.nat{ind < k /\ k < len}). Lib.IntTypes.v b.[ k ] = 0)) (ensures Hacl.Spec.Bignum.Definitions.bn_v b == Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.slice b 0 ind) + Prims.pow2 (Lib.IntTypes.bits t * ind) * Lib.IntTypes.v b.[ ind ])
{ "end_col": 74, "end_line": 369, "start_col": 47, "start_line": 358 }
FStar.Pervasives.Lemma
val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in ()
val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b =
false
null
true
Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[ priv ] <> 0) /\ (forall (k: nat{priv < k /\ k < i}). v b.[ k ] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[ i ] (zeros t SEC) in eq_mask_lemma b.[ i ] (zeros t SEC); assert (if v mask = 0 then v b.[ i ] <> 0 else v b.[ i ] = 0); let res = if v mask = 0 then i else priv in res) 0 in ()
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_and", "Prims.eq2", "Prims.l_or", "Prims.op_LessThan", "Lib.LoopCombinators.repeat_gen", "Hacl.Spec.Bignum.Lib.bn_get_top_index_t", "Hacl.Spec.Bignum.Lib.bn_get_top_index_f", "Prims.l_imp", "Prims.op_GreaterThan", "Prims.op_disEquality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.index", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_Forall", "Prims.op_Equality", "Lib.LoopCombinators.repeati_inductive", "Lib.IntTypes.size_nat", "Lib.IntTypes.max_size_t", "Lib.Sequence.op_String_Access", "Prims.op_Addition", "Prims.bool", "Prims.unit", "Prims._assert", "Lib.IntTypes.eq_mask_lemma", "Lib.IntTypes.zeros", "Lib.IntTypes.int_t", "Lib.IntTypes.eq_mask", "Lib.LoopCombinators.unfold_repeat_gen", "Lib.LoopCombinators.eq_repeat_gen0" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0))
[]
Hacl.Spec.Bignum.Lib.bn_get_top_index_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> FStar.Pervasives.Lemma (ensures (let ind = Hacl.Spec.Bignum.Lib.bn_get_top_index b in ind < len /\ (ind > 0 ==> Lib.IntTypes.v b.[ ind ] <> 0) /\ (forall (k: Prims.nat{ind < k /\ k < len}). Lib.IntTypes.v b.[ k ] = 0)))
{ "end_col": 4, "end_line": 349, "start_col": 2, "start_line": 336 }
FStar.Pervasives.Lemma
val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j)
val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind =
false
null
true
let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[ i ]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[ i ]) (i * pbits) j; assert (v b.[ i ] < pow2 j)
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Prims._assert", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pow2", "Prims.unit", "Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma_aux", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Subtraction", "Lib.Sequence.slice", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.eq2", "Prims.int", "Prims.op_Addition", "Hacl.Spec.Bignum.Definitions.bn_eval1", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.nat", "FStar.Math.Lemmas.pow2_lt_compat", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.op_Modulus" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0))
[]
Hacl.Spec.Bignum.Lib.bn_lt_pow2_index_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> ind: Lib.IntTypes.size_nat{ind / Lib.IntTypes.bits t < len} -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 ind) (ensures (let i = ind / Lib.IntTypes.bits t in Lib.IntTypes.v b.[ i ] < Prims.pow2 (ind % Lib.IntTypes.bits t) /\ Hacl.Spec.Bignum.Definitions.bn_v b == Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.slice b 0 i) + Prims.pow2 (i * Lib.IntTypes.bits t) * Lib.IntTypes.v b.[ i ] /\ Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.slice b (i + 1) len) = 0))
{ "end_col": 27, "end_line": 135, "start_col": 42, "start_line": 115 }
FStar.Pervasives.Lemma
val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i))
val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i =
false
null
true
let pbits = bits t in calc ( == ) { bn_v c / pow2 (pbits * i); ( == ) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); ( == ) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); ( == ) { (bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i))) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i))
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Division", "Prims.pow2", "FStar.Mul.op_Star", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Addition", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "FStar.Math.Lemmas.division_addition_lemma", "FStar.Math.Lemmas.small_division_lemma_1", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Lib.IntTypes.bits" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} ->
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i))
[]
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i < len} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Lib.bn_div_pow2 b i) == Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 (Lib.IntTypes.bits t * i))
{ "end_col": 60, "end_line": 201, "start_col": 35, "start_line": 190 }
FStar.Pervasives.Lemma
val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j))
val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind =
false
null
true
let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[ i ] >>. size j in calc ( == ) { v b.[ i ] / pow2 j; ( == ) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; ( == ) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); ( == ) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); ( == ) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); ( == ) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j))
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "Prims.op_Subtraction", "Prims.unit", "FStar.Calc.calc_finish", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_index", "Prims.squash", "FStar.Math.Lemmas.pow2_modulo_division_lemma_1", "FStar.Math.Lemmas.division_multiplication_lemma", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.euclidean_div_axiom", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.size" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j))
[]
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_aux_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> ind: Lib.IntTypes.size_nat{ind / Lib.IntTypes.bits t < len} -> FStar.Pervasives.Lemma (ensures (let i = ind / Lib.IntTypes.bits t in let j = ind % Lib.IntTypes.bits t in Lib.IntTypes.v (b.[ i ] >>. Lib.IntTypes.size j) == Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 ind % Prims.pow2 (Lib.IntTypes.bits t - j)) )
{ "end_col": 58, "end_line": 65, "start_col": 44, "start_line": 45 }
FStar.Pervasives.Lemma
val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); ()
val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 =
false
null
true
let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let p1, p2 = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k: nat{k < i}). (if v bit = 1 then p1.[ k ] == b2.[ k ] /\ p2.[ k ] == b1.[ k ] else p1.[ k ] == b1.[ k ] /\ p2.[ k ] == b2.[ k ])) /\ (forall (k: nat{i <= k /\ k < len}). p1.[ k ] == b1.[ k ] /\ p2.[ k ] == b2.[ k ])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[ i ] p2.[ i ]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); ()
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.unit", "Prims._assert", "Prims.op_Equality", "Prims.int", "Prims.eq2", "Lib.Sequence.eq_intro", "Prims.bool", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "FStar.Pervasives.Native.Mktuple2", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Lib.cswap2_f", "Prims.l_Forall", "Prims.nat", "Prims.op_LessThan", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.LoopCombinators.repeati_inductive", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Lib.lemma_cswap2_step", "Lib.LoopCombinators.unfold_repeati", "Prims.op_Addition", "Lib.LoopCombinators.eq_repeati0", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2))
[]
Hacl.Spec.Bignum.Lib.cswap2_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
bit: Hacl.Spec.Bignum.Definitions.limb t {Lib.IntTypes.v bit <= 1} -> b1: Hacl.Spec.Bignum.Definitions.lbignum t len -> b2: Hacl.Spec.Bignum.Definitions.lbignum t len -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ p1 p2 = _ in (match Lib.IntTypes.v bit = 1 with | true -> p1 == b2 /\ p2 == b1 | _ -> p1 == b1 /\ p2 == b2) <: Type0) <: Type0))
{ "end_col": 4, "end_line": 309, "start_col": 36, "start_line": 290 }
FStar.Pervasives.Lemma
val bn_get_bits_limb_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma (v (bn_get_bits_limb n ind) == bn_v n / pow2 ind % pow2 (bits t))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_bits_limb_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in bn_get_ith_bit_aux_lemma n ind; assert (v p1 == bn_v n / pow2 ind % pow2 (pbits - j)); if j = 0 then () else begin bn_get_bits_limb_aux_lemma n ind; if i + 1 < nLen then begin let p2 = n.[i + 1] <<. (size (pbits - j)) in calc (==) { v p2 % pow2 (pbits - j); (==) { } v n.[i + 1] * pow2 (pbits - j) % pow2 pbits % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (v n.[i + 1] * pow2 (pbits - j)) (pbits - j) pbits } v n.[i + 1] * pow2 (pbits - j) % pow2 (pbits - j); (==) { Math.Lemmas.multiple_modulo_lemma (v n.[i + 1]) (pow2 (pbits - j)) } 0; }; let p3 = p1 |. p2 in logor_disjoint p1 p2 (pbits - j); assert (v p3 == v p1 + v p2); bn_eval_index n (i + 1); assert (res == v p1 + v p2); assert (ind / bits t + 1 < nLen && 0 < ind % bits t) end else begin bn_eval_bound n nLen; assert (bn_v n < pow2 (nLen * pbits)); Math.Lemmas.lemma_div_lt_nat (bn_v n) (nLen * pbits) ((i + 1) * pbits); Math.Lemmas.pow2_minus (nLen * pbits) ((i + 1) * pbits); assert (bn_v n / pow2 ((i + 1) * pbits) < pow2 0); assert_norm (pow2 0 = 1); assert (res == v p1) end end
val bn_get_bits_limb_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma (v (bn_get_bits_limb n ind) == bn_v n / pow2 ind % pow2 (bits t)) let bn_get_bits_limb_lemma #t #nLen n ind =
false
null
true
let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[ i ] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in bn_get_ith_bit_aux_lemma n ind; assert (v p1 == bn_v n / pow2 ind % pow2 (pbits - j)); if j = 0 then () else (bn_get_bits_limb_aux_lemma n ind; if i + 1 < nLen then let p2 = n.[ i + 1 ] <<. (size (pbits - j)) in calc ( == ) { v p2 % pow2 (pbits - j); ( == ) { () } v n.[ i + 1 ] * pow2 (pbits - j) % pow2 pbits % pow2 (pbits - j); ( == ) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (v n.[ i + 1 ] * pow2 (pbits - j)) (pbits - j) pbits } v n.[ i + 1 ] * pow2 (pbits - j) % pow2 (pbits - j); ( == ) { Math.Lemmas.multiple_modulo_lemma (v n.[ i + 1 ]) (pow2 (pbits - j)) } 0; }; let p3 = p1 |. p2 in logor_disjoint p1 p2 (pbits - j); assert (v p3 == v p1 + v p2); bn_eval_index n (i + 1); assert (res == v p1 + v p2); assert (ind / bits t + 1 < nLen && 0 < ind % bits t) else (bn_eval_bound n nLen; assert (bn_v n < pow2 (nLen * pbits)); Math.Lemmas.lemma_div_lt_nat (bn_v n) (nLen * pbits) ((i + 1) * pbits); Math.Lemmas.pow2_minus (nLen * pbits) ((i + 1) * pbits); assert (bn_v n / pow2 ((i + 1) * pbits) < pow2 0); assert_norm (pow2 0 = 1); assert (res == v p1)))
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "Prims._assert", "Prims.op_AmpAmp", "Prims.op_Modulus", "Prims.unit", "Prims.eq2", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Definitions.bn_eval_index", "Lib.IntTypes.logor_disjoint", "Prims.op_Subtraction", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Bar_Dot", "FStar.Calc.calc_finish", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1", "FStar.Math.Lemmas.multiple_modulo_lemma", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.size", "FStar.Pervasives.assert_norm", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Math.Lemmas.pow2_minus", "FStar.Math.Lemmas.lemma_div_lt_nat", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Hacl.Spec.Bignum.Lib.bn_get_bits_limb_aux_lemma", "Hacl.Spec.Bignum.Lib.bn_get_ith_bit_aux_lemma", "Lib.IntTypes.op_Greater_Greater_Dot" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b) let bn_low_bound_bits_lemma #t #len b = let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b) val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t let bn_get_bits_limb #t #nLen n ind = let i = ind / bits t in let j = ind % bits t in let p1 = n.[i] >>. size j in let p2 = if i + 1 < nLen && 0 < j then p1 |. (n.[i + 1] <<. (size (bits t - j))) else p1 in p2 val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1) let bn_get_bits_limb_aux_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in calc (==) { bn_v n / pow2 ind % pow2 pbits; (==) { Math.Lemmas.euclidean_division_definition res (pow2 (pbits - j)) } res / pow2 (pbits - j) * pow2 (pbits - j) + res % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } res / pow2 (pbits - j) * pow2 (pbits - j) + bn_v n / pow2 ind % pow2 (pbits - j); (==) { bn_get_ith_bit_aux_lemma n ind } res / pow2 (pbits - j) * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } bn_v n / pow2 ind / pow2 (pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.division_multiplication_lemma (bn_v n) (pow2 ind) (pow2 (pbits - j)) } bn_v n / (pow2 ind * pow2 (pbits - j)) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_plus ind (pbits - j) } bn_v n / pow2 (ind + pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.euclidean_division_definition ind pbits } bn_v n / pow2 (i * pbits + pbits) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (bn_v n / pow2 (i * pbits + pbits)) pbits (pbits - j) } bn_v n / pow2 (i * pbits + pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.distributivity_add_left i 1 pbits } bn_v n / pow2 ((i + 1) * pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.lemma_mod_mul_distr_l (bn_v n / pow2 ((i + 1) * pbits)) (pow2 (pbits - j)) (pow2 pbits) } bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1; } val bn_get_bits_limb_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma (v (bn_get_bits_limb n ind) == bn_v n / pow2 ind % pow2 (bits t))
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_bits_limb_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma (v (bn_get_bits_limb n ind) == bn_v n / pow2 ind % pow2 (bits t))
[]
Hacl.Spec.Bignum.Lib.bn_get_bits_limb_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen -> ind: Lib.IntTypes.size_nat{ind / Lib.IntTypes.bits t < nLen} -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v (Hacl.Spec.Bignum.Lib.bn_get_bits_limb n ind) == Hacl.Spec.Bignum.Definitions.bn_v n / Prims.pow2 ind % Prims.pow2 (Lib.IntTypes.bits t))
{ "end_col": 5, "end_line": 500, "start_col": 43, "start_line": 463 }
FStar.Pervasives.Lemma
val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_get_bits_limb_aux_lemma #t #nLen n ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in calc (==) { bn_v n / pow2 ind % pow2 pbits; (==) { Math.Lemmas.euclidean_division_definition res (pow2 (pbits - j)) } res / pow2 (pbits - j) * pow2 (pbits - j) + res % pow2 (pbits - j); (==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } res / pow2 (pbits - j) * pow2 (pbits - j) + bn_v n / pow2 ind % pow2 (pbits - j); (==) { bn_get_ith_bit_aux_lemma n ind } res / pow2 (pbits - j) * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } bn_v n / pow2 ind / pow2 (pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.division_multiplication_lemma (bn_v n) (pow2 ind) (pow2 (pbits - j)) } bn_v n / (pow2 ind * pow2 (pbits - j)) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_plus ind (pbits - j) } bn_v n / pow2 (ind + pbits - j) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.euclidean_division_definition ind pbits } bn_v n / pow2 (i * pbits + pbits) % pow2 j * pow2 (pbits - j) + v p1; (==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (bn_v n / pow2 (i * pbits + pbits)) pbits (pbits - j) } bn_v n / pow2 (i * pbits + pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.distributivity_add_left i 1 pbits } bn_v n / pow2 ((i + 1) * pbits) * pow2 (pbits - j) % pow2 pbits + v p1; (==) { Math.Lemmas.lemma_mod_mul_distr_l (bn_v n / pow2 ((i + 1) * pbits)) (pow2 (pbits - j)) (pow2 pbits) } bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1; }
val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1) let bn_get_bits_limb_aux_lemma #t #nLen n ind =
false
null
true
let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[ i ] >>. size j in let res = bn_v n / pow2 ind % pow2 pbits in calc ( == ) { bn_v n / pow2 ind % pow2 pbits; ( == ) { Math.Lemmas.euclidean_division_definition res (pow2 (pbits - j)) } (res / pow2 (pbits - j)) * pow2 (pbits - j) + res % pow2 (pbits - j); ( == ) { Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } (res / pow2 (pbits - j)) * pow2 (pbits - j) + bn_v n / pow2 ind % pow2 (pbits - j); ( == ) { bn_get_ith_bit_aux_lemma n ind } (res / pow2 (pbits - j)) * pow2 (pbits - j) + v p1; ( == ) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v n / pow2 ind) (pbits - j) pbits } (bn_v n / pow2 ind / pow2 (pbits - j) % pow2 j) * pow2 (pbits - j) + v p1; ( == ) { Math.Lemmas.division_multiplication_lemma (bn_v n) (pow2 ind) (pow2 (pbits - j)) } (bn_v n / (pow2 ind * pow2 (pbits - j)) % pow2 j) * pow2 (pbits - j) + v p1; ( == ) { Math.Lemmas.pow2_plus ind (pbits - j) } (bn_v n / pow2 (ind + pbits - j) % pow2 j) * pow2 (pbits - j) + v p1; ( == ) { Math.Lemmas.euclidean_division_definition ind pbits } (bn_v n / pow2 (i * pbits + pbits) % pow2 j) * pow2 (pbits - j) + v p1; ( == ) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (bn_v n / pow2 (i * pbits + pbits)) pbits (pbits - j) } (bn_v n / pow2 (i * pbits + pbits)) * pow2 (pbits - j) % pow2 pbits + v p1; ( == ) { Math.Lemmas.distributivity_add_left i 1 pbits } (bn_v n / pow2 ((i + 1) * pbits)) * pow2 (pbits - j) % pow2 pbits + v p1; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l (bn_v n / pow2 ((i + 1) * pbits)) (pow2 (pbits - j)) (pow2 pbits) } (bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits) * pow2 (pbits - j) % pow2 pbits + v p1; }
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.squash", "FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1", "Hacl.Spec.Bignum.Lib.bn_get_ith_bit_aux_lemma", "FStar.Math.Lemmas.pow2_modulo_division_lemma_1", "FStar.Math.Lemmas.division_multiplication_lemma", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.size" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; } /// /// % pow2 and / pow2 /// val bn_div_pow2: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i <= len} -> lbignum t (len - i) let bn_div_pow2 #t #len b i = slice b i len val bn_div_pow2_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i < len} -> Lemma (bn_v (bn_div_pow2 b i) == bn_v b / pow2 (bits t * i)) let bn_div_pow2_lemma #t #len c i = let pbits = bits t in calc (==) { bn_v c / pow2 (pbits * i); (==) { bn_eval_split_i c i } (bn_v (slice c 0 i) + pow2 (pbits * i) * bn_v (slice c i len)) / pow2 (pbits * i); (==) { Math.Lemmas.division_addition_lemma (bn_v (slice c 0 i)) (pow2 (pbits * i)) (bn_v (slice c i len)) } bn_v (slice c 0 i) / pow2 (pbits * i) + bn_v (slice c i len); (==) { bn_eval_bound (slice c 0 i) i; Math.Lemmas.small_division_lemma_1 (bn_v (slice c 0 i)) (pow2 (pbits * i)) } bn_v (slice c i len); }; assert (bn_v (slice c i len) == bn_v c / pow2 (pbits * i)) val bn_mod_pow2: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> lbignum t i let bn_mod_pow2 #t #aLen a i = sub a 0 i val bn_mod_pow2_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (bn_v (bn_mod_pow2 a i) == bn_v a % pow2 (bits t * i)) let bn_mod_pow2_lemma #t #aLen a i = let pbits = bits t in calc (==) { bn_v a % pow2 (pbits * i); (==) { bn_eval_split_i a i } (bn_v (slice a 0 i) + pow2 (pbits * i) * bn_v (slice a i aLen)) % pow2 (pbits * i); (==) { Math.Lemmas.modulo_addition_lemma (bn_v (slice a 0 i)) (pow2 (pbits * i)) (bn_v (slice a i aLen)) } (bn_v (slice a 0 i)) % pow2 (pbits * i); (==) { bn_eval_bound (slice a 0 i) i; Math.Lemmas.small_mod (bn_v (slice a 0 i)) (pow2 (pbits * i)) } bn_v (slice a 0 i); } /// /// Conditional swap /// //the same as in curve25519 val lemma_cswap2_step: #t:limb_t -> bit:limb t{v bit <= 1} -> p1:limb t -> p2:limb t -> Lemma (let mask = uint #t 0 -. bit in let dummy = mask &. (p1 ^. p2) in let p1' = p1 ^. dummy in let p2' = p2 ^. dummy in if v bit = 1 then p1' == p2 /\ p2' == p1 else p1' == p1 /\ p2' == p2) let lemma_cswap2_step #t bit p1 p2 = let mask = uint #t 0 -. bit in assert (v bit == 0 ==> v mask == 0); assert (v bit == 1 ==> v mask == pow2 (bits t) - 1); let dummy = mask &. (p1 ^. p2) in logand_lemma mask (p1 ^. p2); assert (v bit == 1 ==> v dummy == v (p1 ^. p2)); assert (v bit == 0 ==> v dummy == 0); let p1' = p1 ^. dummy in assert (v dummy == v (if v bit = 1 then (p1 ^. p2) else uint #t 0)); logxor_lemma p1 p2; let p2' = p2 ^. dummy in logxor_lemma p2 p1 val cswap2_f: #t:limb_t -> #len:size_nat -> mask:limb t -> i:nat{i < len} -> tuple2 (lbignum t len) (lbignum t len) -> tuple2 (lbignum t len) (lbignum t len) let cswap2_f #t #len mask i (p1, p2) = let dummy = mask &. (p1.[i] ^. p2.[i]) in let p1 = p1.[i] <- p1.[i] ^. dummy in let p2 = p2.[i] <- p2.[i] ^. dummy in (p1, p2) val cswap2: #t:limb_t -> #len:size_nat -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> tuple2 (lbignum t len) (lbignum t len) let cswap2 #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.repeati len (cswap2_f #t #len mask) (b1, b2) val cswap2_lemma: #t:limb_t -> #len:size_nat -> bit:limb t{v bit <= 1} -> b1:lbignum t len -> b2:lbignum t len -> Lemma (let (p1, p2) = cswap2 bit b1 b2 in (if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) let cswap2_lemma #t #len bit b1 b2 = let mask = uint #t 0 -. bit in Loops.eq_repeati0 len (cswap2_f #t #len mask) (b1, b2); let (p1, p2) = Loops.repeati_inductive #(tuple2 (lbignum t len) (lbignum t len)) len (fun i (p1, p2) -> (p1, p2) == Loops.repeati i (cswap2_f #t #len mask) (b1, b2) /\ (forall (k:nat{k < i}). (if v bit = 1 then p1.[k] == b2.[k] /\ p2.[k] == b1.[k] else p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) /\ (forall (k:nat{i <= k /\ k < len}). p1.[k] == b1.[k] /\ p2.[k] == b2.[k])) (fun i (p1, p2) -> Loops.unfold_repeati (i + 1) (cswap2_f #t #len mask) (b1, b2) i; lemma_cswap2_step bit p1.[i] p2.[i]; cswap2_f #t #len mask i (p1, p2)) (b1, b2) in assert (if v bit = 1 then (eq_intro p1 b2; p1 == b2) else (eq_intro p1 b1; p1 == b1)); assert (if v bit = 1 then (eq_intro p2 b1; p2 == b1) else (eq_intro p2 b2; p2 == b2)); //eq_intro p1 (if v bit = 1 then b2 else b1); //eq_intro p2 (if v bit = 1 then b1 else b2); () let bn_get_top_index_t (len:size_nat) (i:nat{i <= len}) = x:nat{x < len} val bn_get_top_index_f: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:nat{i < len} -> priv:bn_get_top_index_t len i -> bn_get_top_index_t len (i + 1) let bn_get_top_index_f #t #len b i priv = let mask = eq_mask b.[i] (zeros t SEC) in if v mask = 0 then i else priv val bn_get_top_index: #t:limb_t -> #len:size_pos -> b:lbignum t len -> res:size_nat{res < len} let bn_get_top_index #t #len b = Loops.repeat_gen len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 val bn_get_top_index_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (let ind = bn_get_top_index #t #len b in ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) let bn_get_top_index_lemma #t #len b = Loops.eq_repeat_gen0 len (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0; let res = Loops.repeati_inductive #size_nat len (fun i priv -> priv == Loops.repeat_gen i (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 /\ priv < len /\ (priv > 0 ==> v b.[priv] <> 0) /\ (forall (k:nat{priv < k /\ k < i}). v b.[k] = 0)) (fun i priv -> Loops.unfold_repeat_gen (i + 1) (bn_get_top_index_t len) (bn_get_top_index_f #t #len b) 0 i; let mask = eq_mask b.[i] (zeros t SEC) in eq_mask_lemma b.[i] (zeros t SEC); assert (if v mask = 0 then v b.[i] <> 0 else v b.[i] = 0); let res = if v mask = 0 then i else priv in res) 0 in () val bn_get_top_index_eval_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> ind:nat -> Lemma (requires ind < len /\ (ind > 0 ==> v b.[ind] <> 0) /\ (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0)) (ensures bn_v b == bn_v (slice b 0 ind) + pow2 (bits t * ind) * v b.[ind]) let bn_get_top_index_eval_lemma #t #len b ind = let pbits = bits t in assert (forall (k:nat{ind < k /\ k < len}). v b.[k] = 0); bn_eval_split_i b (ind + 1); assert (bn_v b == bn_v (slice b 0 (ind + 1)) + pow2 (pbits * (ind + 1)) * bn_v (slice b (ind + 1) len)); eq_intro (slice b (ind + 1) len) (create (len - ind - 1) (uint #t 0)); bn_eval_zeroes #t (len - ind - 1) (len - ind - 1); assert (bn_v b == bn_v (slice b 0 (ind + 1))); bn_eval_split_i (slice b 0 (ind + 1)) ind; assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * bn_v (slice b ind (ind + 1))); bn_eval1 (slice b ind (ind + 1)); assert (bn_v b == bn_v (slice b 0 ind) + pow2 (pbits * ind) * v b.[ind]) val bn_low_bound_bits: #t:limb_t -> #len:size_pos{bits t * len <= max_size_t} -> b:lbignum t len -> res:size_nat{res / bits t < len} let bn_low_bound_bits #t #len b = bits t * bn_get_top_index b val bn_low_bound_bits_lemma: #t:limb_t -> #len:size_pos -> b:lbignum t len -> Lemma (requires 1 < bn_v b /\ bits t * len <= max_size_t /\ bn_v b % 2 = 1) (ensures pow2 (bn_low_bound_bits b) < bn_v b) let bn_low_bound_bits_lemma #t #len b = let ind = bn_get_top_index #t #len b in bn_get_top_index_lemma #t #len b; bn_get_top_index_eval_lemma #t #len b ind; assert (pow2 (bn_low_bound_bits b) <= bn_v b); if ind = 0 then assert_norm (pow2 0 = 1) else Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bn_low_bound_bits b) val bn_get_bits_limb: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> limb t let bn_get_bits_limb #t #nLen n ind = let i = ind / bits t in let j = ind % bits t in let p1 = n.[i] >>. size j in let p2 = if i + 1 < nLen && 0 < j then p1 |. (n.[i + 1] <<. (size (bits t - j))) else p1 in p2 val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_get_bits_limb_aux_lemma: #t:limb_t -> #nLen:size_nat -> n:lbignum t nLen -> ind:size_nat{ind / bits t < nLen} -> Lemma ( let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[i] >>. size j in bn_v n / pow2 ind % pow2 pbits == bn_v n / pow2 ((i + 1) * pbits) % pow2 pbits * pow2 (pbits - j) % pow2 pbits + v p1)
[]
Hacl.Spec.Bignum.Lib.bn_get_bits_limb_aux_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen -> ind: Lib.IntTypes.size_nat{ind / Lib.IntTypes.bits t < nLen} -> FStar.Pervasives.Lemma (ensures (let pbits = Lib.IntTypes.bits t in let i = ind / pbits in let j = ind % pbits in let p1 = n.[ i ] >>. Lib.IntTypes.size j in Hacl.Spec.Bignum.Definitions.bn_v n / Prims.pow2 ind % Prims.pow2 pbits == (Hacl.Spec.Bignum.Definitions.bn_v n / Prims.pow2 ((i + 1) * pbits) % Prims.pow2 pbits) * Prims.pow2 (pbits - j) % Prims.pow2 pbits + Lib.IntTypes.v p1))
{ "end_col": 5, "end_line": 453, "start_col": 47, "start_line": 424 }
FStar.Pervasives.Lemma
val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "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.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "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 } ]
false
let bn_set_ith_bit_lemma #t #len input ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[i] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[i] <- input.[i] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[i]) b j; assert (v inp.[i] == v input.[i] + v b); calc (==) { bn_v inp; (==) { bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) } bn_v (slice inp 0 (i + 1)); (==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); (==) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i]; (==) { } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b); (==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b; (==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind; (==) { } bn_v input + pow2 ind; }
val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) let bn_set_ith_bit_lemma #t #len input ind =
false
null
true
let pbits = bits t in let i = ind / pbits in let j = ind % pbits in bn_lt_pow2_index_lemma #t #len input ind; assert (v input.[ i ] < pow2 j); let b = uint #t 1 <<. size j in let inp = input.[ i ] <- input.[ i ] |. b in FStar.Math.Lemmas.pow2_lt_compat pbits j; FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits); assert (v b == pow2 j); logor_disjoint (input.[ i ]) b j; assert (v inp.[ i ] == v input.[ i ] + v b); calc ( == ) { bn_v inp; ( == ) { (bn_eval_split_i #t #len inp (i + 1); bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1)) } bn_v (slice inp 0 (i + 1)); ( == ) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i } bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1)); ( == ) { bn_eval1 (slice inp i (i + 1)) } bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[ i ]; ( == ) { bn_eval_extensionality_j input inp i } bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[ i ]; ( == ) { () } bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[ i ] + v b); ( == ) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[ i ]) (v b) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[ i ] + pow2 (i * pbits) * v b; ( == ) { (Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits) } bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[ i ] + pow2 ind; ( == ) { () } bn_v input + pow2 ind; }
{ "checked_file": "Hacl.Spec.Bignum.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Lib.fst" }
[ "lemma" ]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.bits", "FStar.Calc.calc_finish", "Prims.nat", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.op_Addition", "Prims.pow2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Lib.Sequence.slice", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.squash", "Hacl.Spec.Bignum.Definitions.bn_eval1", "FStar.Math.Lemmas.distributivity_add_right", "FStar.Math.Lemmas.euclidean_division_definition", "FStar.Math.Lemmas.pow2_plus", "Prims._assert", "Prims.int", "Lib.IntTypes.logor_disjoint", "Prims.l_or", "Lib.IntTypes.range", "Prims.op_GreaterThan", "FStar.Math.Lemmas.modulo_lemma", "FStar.Math.Lemmas.pow2_lt_compat", "Lib.Sequence.lseq", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Lib.IntTypes.logor", "Lib.Sequence.index", "Prims.l_Forall", "Prims.op_LessThanOrEqual", "Prims.l_imp", "Prims.op_disEquality", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.uint", "Lib.IntTypes.size", "Hacl.Spec.Bignum.Lib.bn_lt_pow2_index_lemma", "Prims.op_Modulus" ]
[]
module Hacl.Spec.Bignum.Lib open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1 val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2) let limb_get_ith_bit_lemma #t a i = let tmp1 = a >>. size i in let tmp2 = tmp1 &. uint #t 1 in mod_mask_lemma tmp1 1ul; assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1)); assert (v tmp2 == v a / pow2 i % 2) val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t let bn_get_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in limb_get_ith_bit input.[i] j val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (let i = ind / bits t in let j = ind % bits t in v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j)) let bn_get_ith_bit_aux_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = b.[i] >>. size j in calc (==) { v b.[i] / pow2 j; (==) { bn_eval_index b i } (bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits } (bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j); (==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) } (bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j); (==) { Math.Lemmas.pow2_plus (pbits * i) j } (bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j); (==) { Math.Lemmas.euclidean_div_axiom ind pbits } (bn_v b / pow2 ind) % pow2 (pbits - j); }; assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j)) val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) let bn_get_ith_bit_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in let res = limb_get_ith_bit b.[i] j in limb_get_ith_bit_lemma b.[i] j; calc (==) { v b.[i] / pow2 j % 2; (==) { bn_get_ith_bit_aux_lemma b ind } (bn_v b / pow2 ind) % pow2 (pbits - j) % 2; (==) { assert_norm (pow2 1 = 2); Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) } (bn_v b / pow2 ind) % 2; }; assert (v res == bn_v b / pow2 ind % 2) val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len let bn_set_ith_bit #t #len input ind = let i = ind / bits t in let j = ind % bits t in let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in inp val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c) (ensures b < pow2 d) let bn_set_ith_bit_lemma_aux a b c d = Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c; assert ((a + b * pow2 c) / pow2 c < pow2 d); Math.Lemmas.lemma_div_plus a b (pow2 c); assert (a / pow2 c + b < pow2 d); Math.Lemmas.small_division_lemma_1 a (pow2 c) val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma (requires bn_v b < pow2 ind) (ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\ bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\ bn_v (slice b (i + 1) len) = 0)) let bn_lt_pow2_index_lemma #t #len b ind = let pbits = bits t in let i = ind / pbits in let j = ind % pbits in Math.Lemmas.euclidean_division_definition ind (pbits); assert (bn_v b < pow2 (i * pbits + j)); Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j); assert (bn_v b < pow2 (i * pbits + pbits)); bn_eval_split_i #t #len b (i + 1); bn_eval_bound (slice b 0 (i + 1)) (i + 1); bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0; assert (bn_v b == bn_v (slice b 0 (i + 1))); bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i; bn_eval1 (slice b i (i + 1)); assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]); bn_eval_bound #t #i (slice b 0 i) i; bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j; assert (v b.[i] < pow2 j) val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i)
false
false
Hacl.Spec.Bignum.Lib.fst
{ "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" }
null
val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma (requires bn_v b < pow2 i) (ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i)
[]
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len} -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 i) (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Lib.bn_set_ith_bit b i) == Hacl.Spec.Bignum.Definitions.bn_v b + Prims.pow2 i)
{ "end_col": 3, "end_line": 176, "start_col": 44, "start_line": 142 }