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
val bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot U8.t
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot U8.t = x `U8.logand` bitfield_mask8 lo hi
val bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot U8.t let bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot U8.t =
false
null
false
x `U8.logand` (bitfield_mask8 lo hi)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt8.logand", "LowParse.BitFields.bitfield_mask8" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction let bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end inline_for_extraction let u8_shift_right (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_right` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_right` amount in y // inline_for_extraction // no, because of https://github.com/FStarLang/karamel/issues/102 let get_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #8 (U8.v x) (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op1 = x `U8.shift_left` (8ul `U32.sub` hi) in let op2 = op1 `U8.shift_right` ((8ul `U32.sub` hi) `U32.add` lo) in op2 // inline_for_extraction // no, same let set_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) (v: U8.t { U8.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) (U32.v lo) (U32.v hi) (U8.v v) }) = bitfield_mask_eq_2 8 (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op0 = (U8.lognot 0uy) in let op1 = op0 `U8.shift_right` (8ul `U32.sub` (hi `U32.sub` lo)) in let op2 = op1 `U8.shift_left` lo in let op3 = U8.lognot op2 in let op4 = x `U8.logand` op3 in let op5 = v `U8.shift_left` lo in let op6 = op4 `U8.logor` op5 in op6 inline_for_extraction let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) lo hi }) = if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) inline_for_extraction let not_bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == not_bitfield_mask 8 lo hi }) = U8.lognot (bitfield_mask8 lo hi) inline_for_extraction let u8_shift_left (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_left` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_left` amount in y inline_for_extraction let set_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) lo hi (U8.v v) }) = if lo = hi then begin set_bitfield_empty #8 (U8.v x) lo (U8.v v); x end else set_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) v inline_for_extraction let bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8})
false
false
LowParse.BitFields.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 bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot U8.t
[]
LowParse.BitFields.bitfield_eq8_lhs
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 8} -> FStar.UInt8.t
{ "end_col": 36, "end_line": 1190, "start_col": 2, "start_line": 1190 }
FStar.Pervasives.Lemma
val nth_size (n1: nat) (n2: nat{n1 <= n2}) (x: U.uint_t n1) (i: nat{i < n2}) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i
val nth_size (n1: nat) (n2: nat{n1 <= n2}) (x: U.uint_t n1) (i: nat{i < n2}) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) let rec nth_size (n1: nat) (n2: nat{n1 <= n2}) (x: U.uint_t n1) (i: nat{i < n2}) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) =
false
null
true
M.pow2_le_compat n2 n1; if i < n1 then if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) else nth_le_pow2_m #n2 x n1 i
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt.uint_t", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Prims.bool", "LowParse.BitFields.nth_size", "Prims.op_Subtraction", "Prims.op_Division", "Prims.unit", "LowParse.BitFields.nth_le_pow2_m", "FStar.Math.Lemmas.pow2_le_compat", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.pow2", "Prims.eq2", "LowParse.BitFields.nth", "Prims.op_AmpAmp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val nth_size (n1: nat) (n2: nat{n1 <= n2}) (x: U.uint_t n1) (i: nat{i < n2}) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i))
[ "recursion" ]
LowParse.BitFields.nth_size
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n1: Prims.nat -> n2: Prims.nat{n1 <= n2} -> x: FStar.UInt.uint_t n1 -> i: Prims.nat{i < n2} -> FStar.Pervasives.Lemma (ensures x < Prims.pow2 n2 /\ LowParse.BitFields.nth x i == (i < n1 && LowParse.BitFields.nth x i))
{ "end_col": 35, "end_line": 706, "start_col": 2, "start_line": 700 }
FStar.Pervasives.Lemma
val set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end
val set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat{bound <= tot /\ x < pow2 bound}) (lo: nat) (hi: nat{lo <= hi /\ hi <= bound}) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) =
false
null
true
if bound = 0 then set_bitfield_empty x lo v else (M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.pow2", "LowParse.BitFields.ubitfield", "Prims.op_Subtraction", "Prims.op_Equality", "Prims.int", "LowParse.BitFields.set_bitfield_empty", "Prims.bool", "LowParse.BitFields.set_bitfield_size", "Prims.unit", "FStar.Math.Lemmas.pow2_le_compat", "Prims.l_True", "Prims.squash", "LowParse.BitFields.set_bitfield", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound)
[]
LowParse.BitFields.set_bitfield_bound
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> bound: Prims.nat{bound <= tot /\ x < Prims.pow2 bound} -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= bound} -> v: LowParse.BitFields.ubitfield tot (hi - lo) -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.set_bitfield x lo hi v < Prims.pow2 bound)
{ "end_col": 5, "end_line": 770, "start_col": 2, "start_line": 764 }
FStar.Pervasives.Lemma
val get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j )
val get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) =
false
null
true
eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.BitFields.eq_nth", "LowParse.BitFields.get_bitfield", "FStar.UInt.shift_right", "FStar.UInt.shift_left", "Prims.op_Subtraction", "Prims.op_Addition", "Prims.op_LessThan", "LowParse.BitFields.nth_shift_left", "Prims.bool", "Prims.unit", "Prims.int", "LowParse.BitFields.nth_shift_right", "LowParse.BitFields.nth_get_bitfield", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
[]
LowParse.BitFields.get_bitfield_eq_2
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.get_bitfield x lo hi == FStar.UInt.shift_right (FStar.UInt.shift_left x (tot - hi)) (tot - hi + lo))
{ "end_col": 3, "end_line": 856, "start_col": 2, "start_line": 850 }
FStar.Pervasives.Lemma
val bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` (bitfield_mask tot lo hi) == v `U.shift_left` lo)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g ()
val bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` (bitfield_mask tot lo hi) == v `U.shift_left` lo) let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` (bitfield_mask tot lo hi) == v `U.shift_left` lo) =
false
null
true
let y = x `U.logand` (bitfield_mask tot lo hi) in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo)) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then nth_get_bitfield x lo hi (i - lo)) in Classical.move_requires f (); Classical.move_requires g ()
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.BitFields.ubitfield", "Prims.op_Subtraction", "FStar.Classical.move_requires", "Prims.unit", "Prims.eq2", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.BitFields.eq_nth", "Prims.op_LessThan", "LowParse.BitFields.nth_le_pow2_m", "Prims.bool", "LowParse.BitFields.nth_get_bitfield", "LowParse.BitFields.nth_shift_left", "LowParse.BitFields.nth_bitfield_mask", "LowParse.BitFields.nth_logand", "LowParse.BitFields.bitfield_mask", "Prims.op_Addition", "FStar.UInt.shift_left", "LowParse.BitFields.get_bitfield", "FStar.UInt.logand", "Prims.l_True", "Prims.l_iff" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma
false
false
LowParse.BitFields.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 bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` (bitfield_mask tot lo hi) == v `U.shift_left` lo)
[]
LowParse.BitFields.bitfield_eq_shift
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> v: LowParse.BitFields.ubitfield tot (hi - lo) -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.get_bitfield x lo hi == v <==> FStar.UInt.logand x (LowParse.BitFields.bitfield_mask tot lo hi) == FStar.UInt.shift_left v lo )
{ "end_col": 30, "end_line": 610, "start_col": 1, "start_line": 577 }
FStar.Pervasives.Lemma
val get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end
val get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat{mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) =
false
null
true
if mi = 0 then get_bitfield_full x else if mi < tot then (M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then (nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi))); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "LowParse.BitFields.get_bitfield_full", "Prims.bool", "Prims.op_LessThan", "FStar.Math.Lemmas.lemma_mod_lt", "Prims.pow2", "Prims.unit", "FStar.UInt.logand_mask", "LowParse.BitFields.eq_nth", "FStar.UInt.logand", "Prims.op_Subtraction", "LowParse.BitFields.nth_zero", "LowParse.BitFields.nth_get_bitfield", "LowParse.BitFields.nth_pow2_minus_one", "FStar.Math.Lemmas.pow2_le_compat", "Prims.eq2", "LowParse.BitFields.get_bitfield", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0))
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi))
[]
LowParse.BitFields.get_bitfield_hi_lt_pow2
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> mi: Prims.nat{mi <= tot} -> FStar.Pervasives.Lemma (requires LowParse.BitFields.get_bitfield x mi tot == 0) (ensures x < Prims.pow2 mi)
{ "end_col": 5, "end_line": 487, "start_col": 2, "start_line": 472 }
FStar.Pervasives.Lemma
val get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') )
val get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (lo': nat) (hi': nat{lo' <= hi' /\ hi' <= hi - lo}) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) =
false
null
true
eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo'))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.BitFields.eq_nth", "LowParse.BitFields.get_bitfield", "Prims.op_Addition", "Prims.op_LessThan", "LowParse.BitFields.nth_get_bitfield", "Prims.bool", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.l_or", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
[]
LowParse.BitFields.get_bitfield_get_bitfield
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> lo': Prims.nat -> hi': Prims.nat{lo' <= hi' /\ hi' <= hi - lo} -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.get_bitfield (LowParse.BitFields.get_bitfield x lo hi) lo' hi' == LowParse.BitFields.get_bitfield x (lo + lo') (lo + hi'))
{ "end_col": 3, "end_line": 501, "start_col": 2, "start_line": 496 }
Prims.Tot
val u64_shift_right (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_right` (U32.v amount)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount
val u64_shift_right (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_right` (U32.v amount)}) let u64_shift_right (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_right` (U32.v amount)}) =
false
null
false
if amount = 64ul then 0uL else x `U64.shift_right` amount
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt64.t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_Equality", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "Prims.bool", "FStar.UInt64.shift_right", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.UInt.shift_right" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 })
false
false
LowParse.BitFields.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 u64_shift_right (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_right` (U32.v amount)})
[]
LowParse.BitFields.u64_shift_right
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt64.t -> amount: FStar.UInt32.t{FStar.UInt32.v amount <= 64} -> y: FStar.UInt64.t {FStar.UInt64.v y == FStar.UInt.shift_right (FStar.UInt64.v x) (FStar.UInt32.v amount)}
{ "end_col": 59, "end_line": 897, "start_col": 2, "start_line": 897 }
FStar.Pervasives.Lemma
val set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) )
val set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) =
false
null
true
eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.BitFields.eq_nth", "LowParse.BitFields.set_bitfield", "LowParse.BitFields.get_bitfield", "Prims.op_LessThan", "Prims.op_AmpAmp", "LowParse.BitFields.nth_get_bitfield", "Prims.op_Subtraction", "Prims.bool", "Prims.unit", "LowParse.BitFields.nth_set_bitfield", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma
false
false
LowParse.BitFields.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 set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x)
[]
LowParse.BitFields.set_bitfield_get_bitfield
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.set_bitfield x lo hi (LowParse.BitFields.get_bitfield x lo hi) == x)
{ "end_col": 3, "end_line": 625, "start_col": 2, "start_line": 621 }
Prims.Tot
val bitfield_mask64 (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) : Tot (x: U64.t{U64.v x == bitfield_mask 64 lo hi})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end
val bitfield_mask64 (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) : Tot (x: U64.t{U64.v x == bitfield_mask 64 lo hi}) let bitfield_mask64 (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) : Tot (x: U64.t{U64.v x == bitfield_mask 64 lo hi}) =
false
null
false
if lo = hi then 0uL else (bitfield_mask_eq_2 64 lo hi; ((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` (U32.uint_to_t lo))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "FStar.UInt64.__uint_to_t", "Prims.bool", "FStar.UInt64.shift_left", "FStar.UInt64.shift_right", "FStar.UInt64.lognot", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "FStar.UInt32.uint_to_t", "Prims.op_Subtraction", "Prims.unit", "LowParse.BitFields.bitfield_mask_eq_2", "FStar.UInt64.t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt64.n", "FStar.UInt64.v", "LowParse.BitFields.bitfield_mask" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction
false
false
LowParse.BitFields.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 bitfield_mask64 (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) : Tot (x: U64.t{U64.v x == bitfield_mask 64 lo hi})
[]
LowParse.BitFields.bitfield_mask64
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 64} -> x: FStar.UInt64.t{FStar.UInt64.v x == LowParse.BitFields.bitfield_mask 64 lo hi}
{ "end_col": 5, "end_line": 890, "start_col": 2, "start_line": 885 }
Prims.Tot
val u64_shift_left (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_left` (U32.v amount)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount
val u64_shift_left (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_left` (U32.v amount)}) let u64_shift_left (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_left` (U32.v amount)}) =
false
null
false
if amount = 64ul then 0uL else x `U64.shift_left` amount
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt64.t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_Equality", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "Prims.bool", "FStar.UInt64.shift_left", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.UInt.shift_left" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 })
false
false
LowParse.BitFields.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 u64_shift_left (x: U64.t) (amount: U32.t{U32.v amount <= 64}) : Tot (y: U64.t{U64.v y == (U64.v x) `U.shift_left` (U32.v amount)})
[]
LowParse.BitFields.u64_shift_left
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt64.t -> amount: FStar.UInt32.t{FStar.UInt32.v amount <= 64} -> y: FStar.UInt64.t {FStar.UInt64.v y == FStar.UInt.shift_left (FStar.UInt64.v x) (FStar.UInt32.v amount)}
{ "end_col": 58, "end_line": 914, "start_col": 2, "start_line": 914 }
Prims.Tot
val u32_shift_left (x: U32.t) (amount: U32.t{U32.v amount <= 32}) : Tot (y: U32.t{U32.v y == (U32.v x) `U.shift_left` (U32.v amount)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount
val u32_shift_left (x: U32.t) (amount: U32.t{U32.v amount <= 32}) : Tot (y: U32.t{U32.v y == (U32.v x) `U.shift_left` (U32.v amount)}) let u32_shift_left (x: U32.t) (amount: U32.t{U32.v amount <= 32}) : Tot (y: U32.t{U32.v y == (U32.v x) `U.shift_left` (U32.v amount)}) =
false
null
false
if amount = 32ul then 0ul else x `U32.shift_left` amount
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_Equality", "FStar.UInt32.__uint_to_t", "Prims.bool", "FStar.UInt32.shift_left", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt32.n", "FStar.UInt.shift_left" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 })
false
false
LowParse.BitFields.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 u32_shift_left (x: U32.t) (amount: U32.t{U32.v amount <= 32}) : Tot (y: U32.t{U32.v y == (U32.v x) `U.shift_left` (U32.v amount)})
[]
LowParse.BitFields.u32_shift_left
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> amount: FStar.UInt32.t{FStar.UInt32.v amount <= 32} -> y: FStar.UInt32.t {FStar.UInt32.v y == FStar.UInt.shift_left (FStar.UInt32.v x) (FStar.UInt32.v amount)}
{ "end_col": 58, "end_line": 991, "start_col": 2, "start_line": 991 }
FStar.Pervasives.Lemma
val lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end
val lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat{mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) =
false
null
true
if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then (M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "LowParse.BitFields.get_bitfield_zero", "Prims.bool", "Prims.op_LessThan", "LowParse.BitFields.eq_nth", "LowParse.BitFields.get_bitfield", "LowParse.BitFields.nth_pow2_minus_one", "Prims.unit", "LowParse.BitFields.nth_get_bitfield", "FStar.UInt.logand", "Prims.op_Subtraction", "Prims.pow2", "LowParse.BitFields.nth_zero", "FStar.UInt.logand_mask", "FStar.Math.Lemmas.modulo_lemma", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi))
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0))
[]
LowParse.BitFields.lt_pow2_get_bitfield_hi
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> mi: Prims.nat{mi <= tot} -> FStar.Pervasives.Lemma (requires x < Prims.pow2 mi) (ensures LowParse.BitFields.get_bitfield x mi tot == 0)
{ "end_col": 5, "end_line": 463, "start_col": 2, "start_line": 451 }
FStar.Pervasives.Lemma
val bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` (bitfield_mask tot lo hi) == 0)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g ()
val bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` (bitfield_mask tot lo hi) == 0) let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` (bitfield_mask tot lo hi) == 0) =
false
null
true
let y = x `U.logand` (bitfield_mask tot lo hi) in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo)) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then (nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo))) in Classical.move_requires f (); Classical.move_requires g ()
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Classical.move_requires", "Prims.unit", "Prims.eq2", "Prims.int", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.BitFields.eq_nth", "Prims.op_LessThan", "Prims.op_AmpAmp", "LowParse.BitFields.nth_zero", "Prims.op_Subtraction", "LowParse.BitFields.nth_get_bitfield", "Prims.bool", "LowParse.BitFields.nth_bitfield_mask", "LowParse.BitFields.nth_logand", "LowParse.BitFields.bitfield_mask", "Prims.op_Addition", "LowParse.BitFields.ubitfield", "LowParse.BitFields.get_bitfield", "FStar.UInt.logand", "Prims.l_True", "Prims.l_iff" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma
false
false
LowParse.BitFields.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 bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` (bitfield_mask tot lo hi) == 0)
[]
LowParse.BitFields.bitfield_is_zero
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.get_bitfield x lo hi == 0 <==> FStar.UInt.logand x (LowParse.BitFields.bitfield_mask tot lo hi) == 0)
{ "end_col": 30, "end_line": 565, "start_col": 1, "start_line": 535 }
Prims.Tot
val set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t{U64.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U64.t{U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo)
val set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t{U64.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U64.t{U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v)}) let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t{U64.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U64.t{U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v)}) =
false
null
false
bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` (U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo))) `U64.logor` (v `U64.shift_left` lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt64.t", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "FStar.UInt64.v", "Prims.pow2", "Prims.op_Subtraction", "FStar.UInt64.logor", "FStar.UInt64.logand", "FStar.UInt64.lognot", "FStar.UInt64.shift_left", "FStar.UInt64.shift_right", "FStar.UInt64.__uint_to_t", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "Prims.unit", "LowParse.BitFields.bitfield_mask_eq_2", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt64.n", "LowParse.BitFields.set_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) })
false
false
LowParse.BitFields.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 set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t{U64.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U64.t{U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v)})
[]
LowParse.BitFields.set_bitfield_gen64
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt64.t -> lo: FStar.UInt32.t -> hi: FStar.UInt32.t{FStar.UInt32.v lo < FStar.UInt32.v hi /\ FStar.UInt32.v hi <= 64} -> v: FStar.UInt64.t{FStar.UInt64.v v < Prims.pow2 (FStar.UInt32.v hi - FStar.UInt32.v lo)} -> y: FStar.UInt64.t { FStar.UInt64.v y == LowParse.BitFields.set_bitfield (FStar.UInt64.v x) (FStar.UInt32.v lo) (FStar.UInt32.v hi) (FStar.UInt64.v v) }
{ "end_col": 159, "end_line": 956, "start_col": 2, "start_line": 955 }
Prims.Tot
val not_bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == not_bitfield_mask 16 lo hi})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi)
val not_bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == not_bitfield_mask 16 lo hi}) let not_bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == not_bitfield_mask 16 lo hi}) =
false
null
false
U16.lognot (bitfield_mask16 lo hi)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt16.lognot", "LowParse.BitFields.bitfield_mask16", "FStar.UInt16.t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt16.v", "LowParse.BitFields.not_bitfield_mask" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction
false
false
LowParse.BitFields.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 not_bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == not_bitfield_mask 16 lo hi})
[]
LowParse.BitFields.not_bitfield_mask16
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 16} -> x: FStar.UInt16.t{FStar.UInt16.v x == LowParse.BitFields.not_bitfield_mask 16 lo hi}
{ "end_col": 36, "end_line": 1061, "start_col": 2, "start_line": 1061 }
Prims.Tot
val set_bitfield32 (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) lo hi (U32.v v)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo)
val set_bitfield32 (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) lo hi (U32.v v)}) let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) lo hi (U32.v v)}) =
false
null
false
(x `U32.logand` (not_bitfield_mask32 lo hi)) `U32.logor` (v `u32_shift_left` (U32.uint_to_t lo))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt32.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.pow2", "Prims.op_Subtraction", "FStar.UInt32.logor", "FStar.UInt32.logand", "LowParse.BitFields.not_bitfield_mask32", "LowParse.BitFields.u32_shift_left", "FStar.UInt32.uint_to_t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt32.n", "LowParse.BitFields.set_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) })
false
false
LowParse.BitFields.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 set_bitfield32 (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) lo hi (U32.v v)})
[]
LowParse.BitFields.set_bitfield32
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 32} -> v: FStar.UInt32.t{FStar.UInt32.v v < Prims.pow2 (hi - lo)} -> y: FStar.UInt32.t { FStar.UInt32.v y == LowParse.BitFields.set_bitfield (FStar.UInt32.v x) lo hi (FStar.UInt32.v v) }
{ "end_col": 94, "end_line": 998, "start_col": 2, "start_line": 998 }
FStar.Pervasives.Lemma
val get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i )
val get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) =
false
null
true
eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then nth_set_bitfield x lo hi v (i + lo) else nth_le_pow2_m v (hi - lo) i)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.BitFields.ubitfield", "Prims.op_Subtraction", "LowParse.BitFields.eq_nth", "LowParse.BitFields.get_bitfield", "LowParse.BitFields.set_bitfield", "Prims.op_LessThan", "LowParse.BitFields.nth_set_bitfield", "Prims.op_Addition", "Prims.bool", "LowParse.BitFields.nth_le_pow2_m", "Prims.unit", "LowParse.BitFields.nth_get_bitfield", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma
false
false
LowParse.BitFields.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 get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v)
[]
LowParse.BitFields.get_bitfield_set_bitfield_same
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> v: LowParse.BitFields.ubitfield tot (hi - lo) -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.get_bitfield (LowParse.BitFields.set_bitfield x lo hi v) lo hi == v)
{ "end_col": 3, "end_line": 343, "start_col": 2, "start_line": 336 }
Prims.Tot
val uint16 : uint_t 16 U16.t
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 uint16 : uint_t 16 U16.t = { v = U16.v; uint_to_t = U16.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen16 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen16 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield16 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield16 x lo hi z); logor = (fun x y -> U16.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq16_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq16_rhs x lo hi z); }
val uint16 : uint_t 16 U16.t let uint16:uint_t 16 U16.t =
false
null
false
{ v = U16.v; uint_to_t = U16.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen16 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen16 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield16 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield16 x lo hi z); logor = (fun x y -> U16.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq16_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq16_rhs x lo hi z) }
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "LowParse.BitFields.Mkuint_t", "FStar.UInt16.n", "FStar.UInt16.t", "FStar.UInt16.v", "FStar.UInt16.uint_to_t", "FStar.UInt.uint_t", "Prims.unit", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.BitFields.get_bitfield_gen16", "Prims.eq2", "LowParse.BitFields.get_bitfield", "Prims.pow2", "Prims.op_Subtraction", "LowParse.BitFields.set_bitfield_gen16", "LowParse.BitFields.set_bitfield", "Prims.nat", "LowParse.BitFields.get_bitfield16", "LowParse.BitFields.set_bitfield16", "FStar.UInt16.logor", "FStar.UInt.logor", "LowParse.BitFields.bitfield_eq16_lhs", "LowParse.BitFields.bitfield_eq16_rhs", "Prims.l_iff", "LowParse.BitFields.uint_t" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction let bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end inline_for_extraction let u8_shift_right (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_right` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_right` amount in y // inline_for_extraction // no, because of https://github.com/FStarLang/karamel/issues/102 let get_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #8 (U8.v x) (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op1 = x `U8.shift_left` (8ul `U32.sub` hi) in let op2 = op1 `U8.shift_right` ((8ul `U32.sub` hi) `U32.add` lo) in op2 // inline_for_extraction // no, same let set_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) (v: U8.t { U8.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) (U32.v lo) (U32.v hi) (U8.v v) }) = bitfield_mask_eq_2 8 (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op0 = (U8.lognot 0uy) in let op1 = op0 `U8.shift_right` (8ul `U32.sub` (hi `U32.sub` lo)) in let op2 = op1 `U8.shift_left` lo in let op3 = U8.lognot op2 in let op4 = x `U8.logand` op3 in let op5 = v `U8.shift_left` lo in let op6 = op4 `U8.logor` op5 in op6 inline_for_extraction let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) lo hi }) = if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) inline_for_extraction let not_bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == not_bitfield_mask 8 lo hi }) = U8.lognot (bitfield_mask8 lo hi) inline_for_extraction let u8_shift_left (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_left` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_left` amount in y inline_for_extraction let set_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) lo hi (U8.v v) }) = if lo = hi then begin set_bitfield_empty #8 (U8.v x) lo (U8.v v); x end else set_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) v inline_for_extraction let bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot U8.t = x `U8.logand` bitfield_mask8 lo hi inline_for_extraction let bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U8.v x) lo hi (U8.v v) in v `u8_shift_left` U32.uint_to_t lo inline_for_extraction noextract let uint64 : uint_t 64 U64.t = { v = U64.v; uint_to_t = U64.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen64 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen64 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield64 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield64 x lo hi z); logor = (fun x y -> U64.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq64_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq64_rhs x lo hi z); } let uint64_v_eq x = () let uint64_uint_to_t_eq x = () inline_for_extraction noextract let uint32 : uint_t 32 U32.t = { v = U32.v; uint_to_t = U32.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen32 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen32 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield32 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield32 x lo hi z); logor = (fun x y -> U32.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq32_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq32_rhs x lo hi z); } let uint32_v_eq x = () let uint32_uint_to_t_eq x = () inline_for_extraction noextract
false
false
LowParse.BitFields.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 uint16 : uint_t 16 U16.t
[]
LowParse.BitFields.uint16
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.BitFields.uint_t 16 FStar.UInt16.t
{ "end_col": 67, "end_line": 1253, "start_col": 2, "start_line": 1243 }
Prims.Tot
val uint32 : uint_t 32 U32.t
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 uint32 : uint_t 32 U32.t = { v = U32.v; uint_to_t = U32.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen32 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen32 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield32 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield32 x lo hi z); logor = (fun x y -> U32.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq32_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq32_rhs x lo hi z); }
val uint32 : uint_t 32 U32.t let uint32:uint_t 32 U32.t =
false
null
false
{ v = U32.v; uint_to_t = U32.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen32 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen32 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield32 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield32 x lo hi z); logor = (fun x y -> U32.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq32_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq32_rhs x lo hi z) }
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "LowParse.BitFields.Mkuint_t", "FStar.UInt32.n", "FStar.UInt32.t", "FStar.UInt32.v", "FStar.UInt32.uint_to_t", "FStar.UInt.uint_t", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_LessThanOrEqual", "LowParse.BitFields.get_bitfield_gen32", "Prims.eq2", "LowParse.BitFields.get_bitfield", "Prims.pow2", "Prims.op_Subtraction", "LowParse.BitFields.set_bitfield_gen32", "LowParse.BitFields.set_bitfield", "Prims.nat", "LowParse.BitFields.get_bitfield32", "LowParse.BitFields.set_bitfield32", "FStar.UInt32.logor", "FStar.UInt.logor", "LowParse.BitFields.bitfield_eq32_lhs", "LowParse.BitFields.bitfield_eq32_rhs", "Prims.l_iff", "LowParse.BitFields.uint_t" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction let bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end inline_for_extraction let u8_shift_right (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_right` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_right` amount in y // inline_for_extraction // no, because of https://github.com/FStarLang/karamel/issues/102 let get_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #8 (U8.v x) (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op1 = x `U8.shift_left` (8ul `U32.sub` hi) in let op2 = op1 `U8.shift_right` ((8ul `U32.sub` hi) `U32.add` lo) in op2 // inline_for_extraction // no, same let set_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) (v: U8.t { U8.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) (U32.v lo) (U32.v hi) (U8.v v) }) = bitfield_mask_eq_2 8 (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op0 = (U8.lognot 0uy) in let op1 = op0 `U8.shift_right` (8ul `U32.sub` (hi `U32.sub` lo)) in let op2 = op1 `U8.shift_left` lo in let op3 = U8.lognot op2 in let op4 = x `U8.logand` op3 in let op5 = v `U8.shift_left` lo in let op6 = op4 `U8.logor` op5 in op6 inline_for_extraction let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) lo hi }) = if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) inline_for_extraction let not_bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == not_bitfield_mask 8 lo hi }) = U8.lognot (bitfield_mask8 lo hi) inline_for_extraction let u8_shift_left (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_left` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_left` amount in y inline_for_extraction let set_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) lo hi (U8.v v) }) = if lo = hi then begin set_bitfield_empty #8 (U8.v x) lo (U8.v v); x end else set_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) v inline_for_extraction let bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot U8.t = x `U8.logand` bitfield_mask8 lo hi inline_for_extraction let bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U8.v x) lo hi (U8.v v) in v `u8_shift_left` U32.uint_to_t lo inline_for_extraction noextract let uint64 : uint_t 64 U64.t = { v = U64.v; uint_to_t = U64.uint_to_t; v_uint_to_t = (fun _ -> ()); uint_to_t_v = (fun _ -> ()); get_bitfield_gen = (fun x lo hi -> get_bitfield_gen64 x lo hi); set_bitfield_gen = (fun x lo hi z -> set_bitfield_gen64 x lo hi z); get_bitfield = (fun x lo hi -> get_bitfield64 x lo hi); set_bitfield = (fun x lo hi z -> set_bitfield64 x lo hi z); logor = (fun x y -> U64.logor x y); bitfield_eq_lhs = (fun x lo hi -> bitfield_eq64_lhs x lo hi); bitfield_eq_rhs = (fun x lo hi z -> bitfield_eq64_rhs x lo hi z); } let uint64_v_eq x = () let uint64_uint_to_t_eq x = () inline_for_extraction noextract
false
false
LowParse.BitFields.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 uint32 : uint_t 32 U32.t
[]
LowParse.BitFields.uint32
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.BitFields.uint_t 32 FStar.UInt32.t
{ "end_col": 67, "end_line": 1234, "start_col": 2, "start_line": 1224 }
Prims.Tot
val set_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{U8.v y == set_bitfield (U8.v x) lo hi (U8.v v)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) lo hi (U8.v v) }) = if lo = hi then begin set_bitfield_empty #8 (U8.v x) lo (U8.v v); x end else set_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) v
val set_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{U8.v y == set_bitfield (U8.v x) lo hi (U8.v v)}) let set_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{U8.v y == set_bitfield (U8.v x) lo hi (U8.v v)}) =
false
null
false
if lo = hi then (set_bitfield_empty #8 (U8.v x) lo (U8.v v); x) else set_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) v
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.pow2", "Prims.op_Subtraction", "Prims.op_Equality", "Prims.unit", "LowParse.BitFields.set_bitfield_empty", "Prims.bool", "LowParse.BitFields.set_bitfield_gen8", "FStar.UInt32.uint_to_t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt8.n", "LowParse.BitFields.set_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction let bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end inline_for_extraction let u8_shift_right (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_right` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_right` amount in y // inline_for_extraction // no, because of https://github.com/FStarLang/karamel/issues/102 let get_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #8 (U8.v x) (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op1 = x `U8.shift_left` (8ul `U32.sub` hi) in let op2 = op1 `U8.shift_right` ((8ul `U32.sub` hi) `U32.add` lo) in op2 // inline_for_extraction // no, same let set_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) (v: U8.t { U8.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) (U32.v lo) (U32.v hi) (U8.v v) }) = bitfield_mask_eq_2 8 (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op0 = (U8.lognot 0uy) in let op1 = op0 `U8.shift_right` (8ul `U32.sub` (hi `U32.sub` lo)) in let op2 = op1 `U8.shift_left` lo in let op3 = U8.lognot op2 in let op4 = x `U8.logand` op3 in let op5 = v `U8.shift_left` lo in let op6 = op4 `U8.logor` op5 in op6 inline_for_extraction let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) lo hi }) = if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) inline_for_extraction let not_bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == not_bitfield_mask 8 lo hi }) = U8.lognot (bitfield_mask8 lo hi) inline_for_extraction let u8_shift_left (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_left` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_left` amount in y inline_for_extraction let set_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) })
false
false
LowParse.BitFields.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 set_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{U8.v y == set_bitfield (U8.v x) lo hi (U8.v v)})
[]
LowParse.BitFields.set_bitfield8
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 8} -> v: FStar.UInt8.t{FStar.UInt8.v v < Prims.pow2 (hi - lo)} -> y: FStar.UInt8.t {FStar.UInt8.v y == LowParse.BitFields.set_bitfield (FStar.UInt8.v x) lo hi (FStar.UInt8.v v)}
{ "end_col": 70, "end_line": 1184, "start_col": 2, "start_line": 1181 }
Prims.Tot
val get_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t{U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo)
val get_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t{U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi)}) let get_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t{U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi)}) =
false
null
false
get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "FStar.UInt32.shift_right", "FStar.UInt32.shift_left", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "FStar.UInt32.add", "Prims.unit", "LowParse.BitFields.get_bitfield_eq_2", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt32.n", "LowParse.BitFields.get_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32})
false
false
LowParse.BitFields.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 get_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t{U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi)})
[]
LowParse.BitFields.get_bitfield_gen32
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> lo: FStar.UInt32.t -> hi: FStar.UInt32.t{FStar.UInt32.v lo < FStar.UInt32.v hi /\ FStar.UInt32.v hi <= 32} -> y: FStar.UInt32.t { FStar.UInt32.v y == LowParse.BitFields.get_bitfield (FStar.UInt32.v x) (FStar.UInt32.v lo) (FStar.UInt32.v hi) }
{ "end_col": 95, "end_line": 1021, "start_col": 2, "start_line": 1020 }
Prims.Tot
val bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == bitfield_mask 16 lo hi})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end
val bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == bitfield_mask 16 lo hi}) let bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == bitfield_mask 16 lo hi}) =
false
null
false
if lo = hi then 0us else (bitfield_mask_eq_2 16 lo hi; ((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` (U32.uint_to_t lo))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "FStar.UInt16.__uint_to_t", "Prims.bool", "FStar.UInt16.shift_left", "FStar.UInt16.shift_right", "FStar.UInt16.lognot", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "FStar.UInt32.uint_to_t", "Prims.op_Subtraction", "Prims.unit", "LowParse.BitFields.bitfield_mask_eq_2", "FStar.UInt16.t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt16.n", "FStar.UInt16.v", "LowParse.BitFields.bitfield_mask" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction
false
false
LowParse.BitFields.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 bitfield_mask16 (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) : Tot (x: U16.t{U16.v x == bitfield_mask 16 lo hi})
[]
LowParse.BitFields.bitfield_mask16
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 16} -> x: FStar.UInt16.t{FStar.UInt16.v x == LowParse.BitFields.bitfield_mask 16 lo hi}
{ "end_col": 5, "end_line": 1044, "start_col": 2, "start_line": 1039 }
Prims.Tot
val bitfield_mask8 (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (x: U8.t{U8.v x == bitfield_mask 8 lo hi})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end
val bitfield_mask8 (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (x: U8.t{U8.v x == bitfield_mask 8 lo hi}) let bitfield_mask8 (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (x: U8.t{U8.v x == bitfield_mask 8 lo hi}) =
false
null
false
if lo = hi then 0uy else (bitfield_mask_eq_2 8 lo hi; ((U8.lognot 0uy) `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` (U32.uint_to_t lo))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "Prims.bool", "FStar.UInt8.shift_left", "FStar.UInt8.shift_right", "FStar.UInt8.lognot", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "FStar.UInt32.uint_to_t", "Prims.op_Subtraction", "Prims.unit", "LowParse.BitFields.bitfield_mask_eq_2", "FStar.UInt8.t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt8.n", "FStar.UInt8.v", "LowParse.BitFields.bitfield_mask" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction
false
false
LowParse.BitFields.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 bitfield_mask8 (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (x: U8.t{U8.v x == bitfield_mask 8 lo hi})
[]
LowParse.BitFields.bitfield_mask8
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 8} -> x: FStar.UInt8.t{FStar.UInt8.v x == LowParse.BitFields.bitfield_mask 8 lo hi}
{ "end_col": 5, "end_line": 1117, "start_col": 2, "start_line": 1112 }
FStar.Pervasives.Lemma
val get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f ()
val get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat{lo <= hi /\ hi <= tot}) (lo': nat{lo <= lo'}) (hi': nat{lo' <= hi' /\ hi' <= hi}) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) =
false
null
true
let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then (nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo))) in Classical.move_requires f ()
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Classical.move_requires", "Prims.unit", "Prims.eq2", "Prims.int", "LowParse.BitFields.get_bitfield", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.BitFields.eq_nth", "Prims.op_LessThan", "Prims.op_Subtraction", "LowParse.BitFields.nth_zero", "Prims.op_Addition", "LowParse.BitFields.nth_get_bitfield", "Prims.bool", "Prims.l_True", "Prims.l_imp" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma
false
false
LowParse.BitFields.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": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
[]
LowParse.BitFields.get_bitfield_zero_inner
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt.uint_t tot -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= tot} -> lo': Prims.nat{lo <= lo'} -> hi': Prims.nat{lo' <= hi' /\ hi' <= hi} -> FStar.Pervasives.Lemma (ensures LowParse.BitFields.get_bitfield x lo hi == 0 ==> LowParse.BitFields.get_bitfield x lo' hi' == 0)
{ "end_col": 30, "end_line": 525, "start_col": 1, "start_line": 511 }
Prims.Tot
val bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) (v: U64.t{U64.v v < pow2 (hi - lo)}) : Tot (y: U64.t{bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo
val bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) (v: U64.t{U64.v v < pow2 (hi - lo)}) : Tot (y: U64.t{bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v}) let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) (v: U64.t{U64.v v < pow2 (hi - lo)}) : Tot (y: U64.t{bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v}) =
false
null
false
[@@ inline_let ]let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` (U32.uint_to_t lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt64.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.UInt64.v", "Prims.pow2", "Prims.op_Subtraction", "LowParse.BitFields.u64_shift_left", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.BitFields.bitfield_eq_shift", "FStar.UInt64.n", "Prims.l_iff", "Prims.eq2", "LowParse.BitFields.bitfield_eq64_lhs", "LowParse.BitFields.get_bitfield64" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) })
false
false
LowParse.BitFields.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 bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 64}) (v: U64.t{U64.v v < pow2 (hi - lo)}) : Tot (y: U64.t{bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v})
[]
LowParse.BitFields.bitfield_eq64_rhs
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt64.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 64} -> v: FStar.UInt64.t{FStar.UInt64.v v < Prims.pow2 (hi - lo)} -> y: FStar.UInt64.t { LowParse.BitFields.bitfield_eq64_lhs x lo hi == y <==> LowParse.BitFields.get_bitfield64 x lo hi == v }
{ "end_col": 37, "end_line": 939, "start_col": 2, "start_line": 936 }
Prims.Tot
val get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t{U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo)
val get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t{U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi)}) let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t{U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi)}) =
false
null
false
get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); let bf:U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt16.t", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "FStar.UInt16.shift_right", "FStar.UInt32.add", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "FStar.UInt16.shift_left", "Prims.unit", "LowParse.BitFields.get_bitfield_eq_2", "FStar.UInt16.v", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt16.n", "LowParse.BitFields.get_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16})
false
false
LowParse.BitFields.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 get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t{U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi)})
[]
LowParse.BitFields.get_bitfield_gen16
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt16.t -> lo: FStar.UInt32.t -> hi: FStar.UInt32.t{FStar.UInt32.v lo < FStar.UInt32.v hi /\ FStar.UInt32.v hi <= 16} -> y: FStar.UInt16.t { FStar.UInt16.v y == LowParse.BitFields.get_bitfield (FStar.UInt16.v x) (FStar.UInt32.v lo) (FStar.UInt32.v hi) }
{ "end_col": 57, "end_line": 1100, "start_col": 2, "start_line": 1097 }
Prims.Tot
val set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t{U16.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo)
val set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t{U16.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v)}) let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t{U16.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v)}) =
false
null
false
bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` (U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo))) `U16.logor` (v `U16.shift_left` lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt16.t", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "FStar.UInt16.v", "Prims.pow2", "Prims.op_Subtraction", "FStar.UInt16.logor", "FStar.UInt16.logand", "FStar.UInt16.lognot", "FStar.UInt16.shift_left", "FStar.UInt16.shift_right", "FStar.UInt16.__uint_to_t", "FStar.UInt32.sub", "FStar.UInt32.__uint_to_t", "Prims.unit", "LowParse.BitFields.bitfield_mask_eq_2", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt16.n", "LowParse.BitFields.set_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) })
false
false
LowParse.BitFields.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 set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t{U16.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v)})
[]
LowParse.BitFields.set_bitfield_gen16
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt16.t -> lo: FStar.UInt32.t -> hi: FStar.UInt32.t{FStar.UInt32.v lo < FStar.UInt32.v hi /\ FStar.UInt32.v hi <= 16} -> v: FStar.UInt16.t{FStar.UInt16.v v < Prims.pow2 (FStar.UInt32.v hi - FStar.UInt32.v lo)} -> y: FStar.UInt16.t { FStar.UInt16.v y == LowParse.BitFields.set_bitfield (FStar.UInt16.v x) (FStar.UInt32.v lo) (FStar.UInt32.v hi) (FStar.UInt16.v v) }
{ "end_col": 159, "end_line": 1108, "start_col": 2, "start_line": 1107 }
Prims.Tot
val bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo
val bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v}) let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v}) =
false
null
false
[@@ inline_let ]let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` (U32.uint_to_t lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt32.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.pow2", "Prims.op_Subtraction", "LowParse.BitFields.u32_shift_left", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.BitFields.bitfield_eq_shift", "FStar.UInt32.n", "Prims.l_iff", "Prims.eq2", "LowParse.BitFields.bitfield_eq32_lhs", "LowParse.BitFields.get_bitfield32" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) })
false
false
LowParse.BitFields.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 bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 32}) (v: U32.t{U32.v v < pow2 (hi - lo)}) : Tot (y: U32.t{bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v})
[]
LowParse.BitFields.bitfield_eq32_rhs
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 32} -> v: FStar.UInt32.t{FStar.UInt32.v v < Prims.pow2 (hi - lo)} -> y: FStar.UInt32.t { LowParse.BitFields.bitfield_eq32_lhs x lo hi == y <==> LowParse.BitFields.get_bitfield32 x lo hi == v }
{ "end_col": 37, "end_line": 1014, "start_col": 2, "start_line": 1011 }
FStar.Pervasives.Lemma
val logor_disjoint (#n: pos) (a b: U.uint_t n) (m: nat{m <= n}) : Lemma (requires (a % pow2 m == 0 /\ b < pow2 m)) (ensures (U.logor #n a b == a + b))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m
val logor_disjoint (#n: pos) (a b: U.uint_t n) (m: nat{m <= n}) : Lemma (requires (a % pow2 m == 0 /\ b < pow2 m)) (ensures (U.logor #n a b == a + b)) let logor_disjoint (#n: pos) (a b: U.uint_t n) (m: nat{m <= n}) : Lemma (requires (a % pow2 m == 0 /\ b < pow2 m)) (ensures (U.logor #n a b == a + b)) =
false
null
true
if m = 0 then U.logor_lemma_1 a else if m = n then (M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b) else U.logor_disjoint a b m
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "FStar.UInt.logor_lemma_1", "Prims.bool", "Prims.l_or", "Prims.op_GreaterThan", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.unit", "FStar.UInt.logor_commutative", "FStar.Math.Lemmas.modulo_lemma", "Prims.pow2", "FStar.UInt.logor_disjoint", "Prims.eq2", "Prims.op_Modulus", "Prims.op_LessThan", "Prims.squash", "FStar.UInt.logor", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m ))
false
false
LowParse.BitFields.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 logor_disjoint (#n: pos) (a b: U.uint_t n) (m: nat{m <= n}) : Lemma (requires (a % pow2 m == 0 /\ b < pow2 m)) (ensures (U.logor #n a b == a + b))
[]
LowParse.BitFields.logor_disjoint
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> m: Prims.nat{m <= n} -> FStar.Pervasives.Lemma (requires a % Prims.pow2 m == 0 /\ b < Prims.pow2 m) (ensures FStar.UInt.logor a b == a + b)
{ "end_col": 26, "end_line": 254, "start_col": 2, "start_line": 245 }
Prims.Tot
val set_bitfield16 (x: U16.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) (v: U16.t{U16.v v < pow2 (hi - lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) lo hi (U16.v v)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo)
val set_bitfield16 (x: U16.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) (v: U16.t{U16.v v < pow2 (hi - lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) lo hi (U16.v v)}) let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) (v: U16.t{U16.v v < pow2 (hi - lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) lo hi (U16.v v)}) =
false
null
false
(x `U16.logand` (not_bitfield_mask16 lo hi)) `U16.logor` (v `u16_shift_left` (U32.uint_to_t lo))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt16.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.UInt16.v", "Prims.pow2", "Prims.op_Subtraction", "FStar.UInt16.logor", "FStar.UInt16.logand", "LowParse.BitFields.not_bitfield_mask16", "LowParse.BitFields.u16_shift_left", "FStar.UInt32.uint_to_t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt16.n", "LowParse.BitFields.set_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) })
false
false
LowParse.BitFields.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 set_bitfield16 (x: U16.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 16}) (v: U16.t{U16.v v < pow2 (hi - lo)}) : Tot (y: U16.t{U16.v y == set_bitfield (U16.v x) lo hi (U16.v v)})
[]
LowParse.BitFields.set_bitfield16
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt16.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 16} -> v: FStar.UInt16.t{FStar.UInt16.v v < Prims.pow2 (hi - lo)} -> y: FStar.UInt16.t { FStar.UInt16.v y == LowParse.BitFields.set_bitfield (FStar.UInt16.v x) lo hi (FStar.UInt16.v v) }
{ "end_col": 94, "end_line": 1075, "start_col": 2, "start_line": 1075 }
Prims.Tot
val bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U8.v x) lo hi (U8.v v) in v `u8_shift_left` U32.uint_to_t lo
val bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v}) let bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v}) =
false
null
false
[@@ inline_let ]let _ = bitfield_eq_shift (U8.v x) lo hi (U8.v v) in v `u8_shift_left` (U32.uint_to_t lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.pow2", "Prims.op_Subtraction", "LowParse.BitFields.u8_shift_left", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.BitFields.bitfield_eq_shift", "FStar.UInt8.n", "Prims.l_iff", "Prims.eq2", "LowParse.BitFields.bitfield_eq8_lhs", "LowParse.BitFields.get_bitfield8" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction let bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end inline_for_extraction let u8_shift_right (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_right` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_right` amount in y // inline_for_extraction // no, because of https://github.com/FStarLang/karamel/issues/102 let get_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #8 (U8.v x) (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op1 = x `U8.shift_left` (8ul `U32.sub` hi) in let op2 = op1 `U8.shift_right` ((8ul `U32.sub` hi) `U32.add` lo) in op2 // inline_for_extraction // no, same let set_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) (v: U8.t { U8.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) (U32.v lo) (U32.v hi) (U8.v v) }) = bitfield_mask_eq_2 8 (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op0 = (U8.lognot 0uy) in let op1 = op0 `U8.shift_right` (8ul `U32.sub` (hi `U32.sub` lo)) in let op2 = op1 `U8.shift_left` lo in let op3 = U8.lognot op2 in let op4 = x `U8.logand` op3 in let op5 = v `U8.shift_left` lo in let op6 = op4 `U8.logor` op5 in op6 inline_for_extraction let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) lo hi }) = if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) inline_for_extraction let not_bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == not_bitfield_mask 8 lo hi }) = U8.lognot (bitfield_mask8 lo hi) inline_for_extraction let u8_shift_left (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_left` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_left` amount in y inline_for_extraction let set_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) lo hi (U8.v v) }) = if lo = hi then begin set_bitfield_empty #8 (U8.v x) lo (U8.v v); x end else set_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi) v inline_for_extraction let bitfield_eq8_lhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot U8.t = x `U8.logand` bitfield_mask8 lo hi inline_for_extraction let bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) (v: U8.t { U8.v v < pow2 (hi - lo) })
false
false
LowParse.BitFields.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 bitfield_eq8_rhs (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) (v: U8.t{U8.v v < pow2 (hi - lo)}) : Tot (y: U8.t{bitfield_eq8_lhs x lo hi == y <==> (get_bitfield8 x lo hi <: U8.t) == v})
[]
LowParse.BitFields.bitfield_eq8_rhs
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 8} -> v: FStar.UInt8.t{FStar.UInt8.v v < Prims.pow2 (hi - lo)} -> y: FStar.UInt8.t { LowParse.BitFields.bitfield_eq8_lhs x lo hi == y <==> LowParse.BitFields.get_bitfield8 x lo hi == v }
{ "end_col": 36, "end_line": 1200, "start_col": 2, "start_line": 1197 }
Prims.Tot
val set_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t{U32.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v)})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo)
val set_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t{U32.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v)}) let set_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t{U32.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v)}) =
false
null
false
bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` (U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo))) `U32.logor` (v `U32.shift_left` lo)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.op_Subtraction", "FStar.UInt32.logor", "FStar.UInt32.logand", "FStar.UInt32.lognot", "FStar.UInt32.shift_left", "FStar.UInt32.shift_right", "FStar.UInt32.__uint_to_t", "FStar.UInt32.sub", "Prims.unit", "LowParse.BitFields.bitfield_mask_eq_2", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt32.n", "LowParse.BitFields.set_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) })
false
false
LowParse.BitFields.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 set_bitfield_gen32 (x lo: U32.t) (hi: U32.t{U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t{U32.v v < pow2 (U32.v hi - U32.v lo)}) : Tot (y: U32.t{U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v)})
[]
LowParse.BitFields.set_bitfield_gen32
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> lo: FStar.UInt32.t -> hi: FStar.UInt32.t{FStar.UInt32.v lo < FStar.UInt32.v hi /\ FStar.UInt32.v hi <= 32} -> v: FStar.UInt32.t{FStar.UInt32.v v < Prims.pow2 (FStar.UInt32.v hi - FStar.UInt32.v lo)} -> y: FStar.UInt32.t { FStar.UInt32.v y == LowParse.BitFields.set_bitfield (FStar.UInt32.v x) (FStar.UInt32.v lo) (FStar.UInt32.v hi) (FStar.UInt32.v v) }
{ "end_col": 159, "end_line": 1031, "start_col": 2, "start_line": 1030 }
FStar.Pervasives.Lemma
val logand_mask (#n: pos) (a: U.uint_t n) (m: nat{m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m)
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end
val logand_mask (#n: pos) (a: U.uint_t n) (m: nat{m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) let logand_mask (#n: pos) (a: U.uint_t n) (m: nat{m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) =
false
null
true
M.pow2_le_compat n m; if m = 0 then U.logand_lemma_1 a else if m = n then (U.logand_lemma_2 a; M.modulo_lemma a (pow2 m)) else U.logand_mask a m
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "FStar.UInt.logand_lemma_1", "Prims.bool", "Prims.l_or", "Prims.op_GreaterThan", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "FStar.Math.Lemmas.modulo_lemma", "Prims.pow2", "Prims.unit", "FStar.UInt.logand_lemma_2", "FStar.UInt.logand_mask", "FStar.Math.Lemmas.pow2_le_compat", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.UInt.logand", "Prims.op_Subtraction", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\
false
false
LowParse.BitFields.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 logand_mask (#n: pos) (a: U.uint_t n) (m: nat{m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m)
[]
LowParse.BitFields.logand_mask
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
a: FStar.UInt.uint_t n -> m: Prims.nat{m <= n} -> FStar.Pervasives.Lemma (ensures Prims.pow2 m <= Prims.pow2 n /\ FStar.UInt.logand a (Prims.pow2 m - 1) == a % Prims.pow2 m)
{ "end_col": 5, "end_line": 177, "start_col": 2, "start_line": 167 }
Prims.Tot
val get_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (y: U8.t{U8.v y == get_bitfield (U8.v x) lo hi})
[ { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) lo hi }) = if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi)
val get_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (y: U8.t{U8.v y == get_bitfield (U8.v x) lo hi}) let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (y: U8.t{U8.v y == get_bitfield (U8.v x) lo hi}) =
false
null
false
if lo = hi then 0uy else get_bitfield_gen8 x (U32.uint_to_t lo) (U32.uint_to_t hi)
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "Prims.bool", "LowParse.BitFields.get_bitfield_gen8", "FStar.UInt32.uint_to_t", "Prims.eq2", "FStar.UInt.uint_t", "FStar.UInt8.n", "FStar.UInt8.v", "LowParse.BitFields.get_bitfield" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end ) #pop-options let get_bitfield_partition_2 (#tot: pos) (mid: nat { mid <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x 0 mid == get_bitfield y 0 mid /\ get_bitfield x mid tot == get_bitfield y mid tot )) (ensures ( x == y )) = get_bitfield_partition_2_gen 0 mid tot x y; get_bitfield_full x; get_bitfield_full y let rec get_bitfield_partition' (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (l: list nat) : Lemma (requires (get_bitfield_partition_prop x y lo hi l)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) (decreases l) = match l with | [] -> () | mi :: q -> get_bitfield_partition' x y mi hi q; get_bitfield_partition_2_gen lo mi hi x y let get_bitfield_partition = get_bitfield_partition' let rec nth_size (n1: nat) (n2: nat { n1 <= n2 }) (x: U.uint_t n1) (i: nat { i < n2 }) : Lemma (x < pow2 n2 /\ nth #n2 x i == (i < n1 && nth #n1 x i)) = M.pow2_le_compat n2 n1; if i < n1 then begin if i = 0 then () else nth_size (n1 - 1) (n2 - 1) (x / 2) (i - 1) end else nth_le_pow2_m #n2 x n1 i let get_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) : Lemma (x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (get_bitfield #tot1 x lo hi) (get_bitfield #tot2 x lo hi) (fun i -> let y1 = nth #tot2 (get_bitfield #tot1 x lo hi) i in let y2 = nth #tot2 (get_bitfield #tot2 x lo hi) i in nth_get_bitfield #tot2 x lo hi i; assert (y2 == (i < hi - lo && nth #tot2 x (i + lo))); nth_size tot1 tot2 (get_bitfield #tot1 x lo hi) i; assert (y1 == (i < tot1 && nth #tot1 (get_bitfield #tot1 x lo hi) i)); if i < tot1 then begin nth_get_bitfield #tot1 x lo hi i; assert (y1 == (i < hi - lo && nth #tot1 x (i + lo))); if i < hi - lo then nth_size tot1 tot2 x (i + lo) end ) let set_bitfield_size (tot1 tot2: pos) (x: nat { x < pow2 tot1 /\ tot1 <= tot2 }) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot1 }) (v: ubitfield tot1 (hi - lo)) : Lemma (x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat)) = M.pow2_le_compat tot2 tot1; eq_nth #tot2 (set_bitfield #tot1 x lo hi v) (set_bitfield #tot2 x lo hi v) (fun i -> let y1 = nth #tot2 (set_bitfield #tot1 x lo hi v) i in let y2 = nth #tot2 (set_bitfield #tot2 x lo hi v) i in nth_set_bitfield #tot2 x lo hi v i; nth_size tot1 tot2 (set_bitfield #tot1 x lo hi v) i; nth_size tot1 tot2 x i; if i < tot1 then begin nth_set_bitfield #tot1 x lo hi v i; if lo <= i && i < hi then nth_size tot1 tot2 v (i - lo) end ) let set_bitfield_bound (#tot: pos) (x: U.uint_t tot) (bound: nat { bound <= tot /\ x < pow2 bound }) (lo: nat) (hi: nat { lo <= hi /\ hi <= bound }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v < pow2 bound) = if bound = 0 then set_bitfield_empty x lo v else begin M.pow2_le_compat tot bound; M.pow2_le_compat bound (hi - lo); set_bitfield_size bound tot x lo hi v end #push-options "--z3rlimit 64 --z3cliopt smt.arith.nl=false --fuel 0 --ifuel 0" let set_bitfield_set_bitfield_get_bitfield #tot x lo hi lo' hi' v' = set_bitfield_bound (get_bitfield x lo hi) (hi - lo) lo' hi' v' ; let x1 = set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') in let x2 = set_bitfield x (lo + lo') (lo + hi') v' in eq_nth x1 x2 (fun i -> nth_set_bitfield x lo hi (set_bitfield (get_bitfield x lo hi) lo' hi' v') i; nth_set_bitfield x (lo + lo') (lo + hi') v' i ; if lo <= i && i < hi then begin assert (nth x1 i == nth (set_bitfield (get_bitfield x lo hi) lo' hi' v') (i - lo)); nth_set_bitfield (get_bitfield x lo hi) lo' hi' v' (i - lo); if lo' <= i - lo && i - lo < hi' then begin () end else begin assert (nth x2 i == nth x i); assert (nth x1 i == nth (get_bitfield x lo hi) (i - lo)); nth_get_bitfield x lo hi (i - lo); assert (i - lo + lo == i) end end ) #pop-options let mod_1 (x: int) : Lemma (x % 1 == 0) = () let div_1 (x: int) : Lemma (x / 1 == x) = () let get_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo)) = if hi - lo = 0 then begin assert (hi == lo); assert_norm (pow2 0 == 1); mod_1 (x / pow2 lo); get_bitfield_empty #tot x lo end else if hi - lo = tot then begin assert (hi == tot); assert (lo == 0); assert_norm (pow2 0 == 1); div_1 x; M.small_mod x (pow2 tot); get_bitfield_full #tot x end else begin assert (hi - lo < tot); U.shift_right_logand_lemma #tot x (bitfield_mask tot lo hi) lo; U.shift_right_value_lemma #tot (bitfield_mask tot lo hi) lo; M.multiple_division_lemma (pow2 (hi - lo) - 1) (pow2 lo); U.logand_mask #tot (U.shift_right x lo) (hi - lo); U.shift_right_value_lemma #tot x lo end let pow2_m_minus_one_eq (n: nat) (m: nat) : Lemma (requires (m <= n)) (ensures ( (pow2 n - 1) / pow2 m == pow2 (n - m) - 1 )) = M.pow2_le_compat n m; M.pow2_plus (n - m) m; M.division_definition (pow2 n - 1) (pow2 m) (pow2 (n - m) - 1) let get_bitfield_eq_2 (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) = eq_nth (get_bitfield x lo hi) ((x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo)) (fun i -> nth_get_bitfield x lo hi i; nth_shift_right (x `U.shift_left` (tot - hi)) (tot - hi + lo) i; let j = i + (tot - hi + lo) in if j < tot then nth_shift_left x (tot - hi) j ) #restart-solver let bitfield_mask_eq_2 (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( bitfield_mask tot lo hi == U.shift_left #tot (U.lognot 0 `U.shift_right` (tot - (hi - lo))) lo ) = bitfield_mask_eq tot lo hi; pow2_m_minus_one_eq tot (tot - (hi - lo)); U.lemma_lognot_value_mod #tot 0; U.shift_right_value_lemma #tot (pow2 tot - 1) (tot - (hi - lo)) let set_bitfield_eq (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo)) = bitfield_mask_eq_2 tot lo hi module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U16 = FStar.UInt16 module U8 = FStar.UInt8 (* Instantiate to UInt64 *) #push-options "--z3rlimit 32" inline_for_extraction let bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == bitfield_mask 64 lo hi }) = if lo = hi then 0uL else begin bitfield_mask_eq_2 64 lo hi; (U64.lognot 0uL `U64.shift_right` (64ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U64.shift_left` U32.uint_to_t lo end inline_for_extraction let u64_shift_right (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_right` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_right` amount inline_for_extraction let get_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) lo hi }) = (x `U64.logand` bitfield_mask64 lo hi) `u64_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask64 (lo: nat) (hi: nat { lo <= hi /\ hi <= 64 }) : Tot (x: U64.t { U64.v x == not_bitfield_mask 64 lo hi }) = U64.lognot (bitfield_mask64 lo hi) inline_for_extraction let u64_shift_left (x: U64.t) (amount: U32.t { U32.v amount <= 64 }) : Tot (y: U64.t { U64.v y == U64.v x `U.shift_left` U32.v amount }) = if amount = 64ul then 0uL else x `U64.shift_left` amount inline_for_extraction let set_bitfield64 (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) lo hi (U64.v v) }) = (x `U64.logand` not_bitfield_mask64 lo hi) `U64.logor` (v `u64_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq64_lhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) : Tot U64.t = x `U64.logand` bitfield_mask64 lo hi #push-options "--z3rlimit 16" inline_for_extraction let bitfield_eq64_rhs (x: U64.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 64}) (v: U64.t { U64.v v < pow2 (hi - lo) }) : Tot (y: U64.t { bitfield_eq64_lhs x lo hi == y <==> (get_bitfield64 x lo hi <: U64.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U64.v x) lo hi (U64.v v) in v `u64_shift_left` U32.uint_to_t lo #pop-options inline_for_extraction let get_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) : Tot (y: U64.t { U64.v y == get_bitfield (U64.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #64 (U64.v x) (U32.v lo) (U32.v hi); (x `U64.shift_left` (64ul `U32.sub` hi)) `U64.shift_right` ((64ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen64 (x: U64.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 64}) (v: U64.t { U64.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U64.t { U64.v y == set_bitfield (U64.v x) (U32.v lo) (U32.v hi) (U64.v v) }) = bitfield_mask_eq_2 64 (U32.v lo) (U32.v hi); (x `U64.logand` U64.lognot (((U64.lognot 0uL) `U64.shift_right` (64ul `U32.sub` (hi `U32.sub` lo))) `U64.shift_left` lo)) `U64.logor` (v `U64.shift_left` lo) (* Instantiate to UInt32 *) inline_for_extraction let bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == bitfield_mask 32 lo hi }) = if lo = hi then 0ul else begin bitfield_mask_eq_2 32 lo hi; (U32.lognot 0ul `U32.shift_right` (32ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U32.shift_left` U32.uint_to_t lo end inline_for_extraction let u32_shift_right (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_right` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_right` amount inline_for_extraction let get_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) lo hi }) = (x `U32.logand` bitfield_mask32 lo hi) `u32_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask32 (lo: nat) (hi: nat { lo <= hi /\ hi <= 32 }) : Tot (x: U32.t { U32.v x == not_bitfield_mask 32 lo hi }) = U32.lognot (bitfield_mask32 lo hi) inline_for_extraction let u32_shift_left (x: U32.t) (amount: U32.t { U32.v amount <= 32 }) : Tot (y: U32.t { U32.v y == U32.v x `U.shift_left` U32.v amount }) = if amount = 32ul then 0ul else x `U32.shift_left` amount inline_for_extraction let set_bitfield32 (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) lo hi (U32.v v) }) = (x `U32.logand` not_bitfield_mask32 lo hi) `U32.logor` (v `u32_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq32_lhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) : Tot U32.t = x `U32.logand` bitfield_mask32 lo hi inline_for_extraction let bitfield_eq32_rhs (x: U32.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 32}) (v: U32.t { U32.v v < pow2 (hi - lo) }) : Tot (y: U32.t { bitfield_eq32_lhs x lo hi == y <==> (get_bitfield32 x lo hi <: U32.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U32.v x) lo hi (U32.v v) in v `u32_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) : Tot (y: U32.t { U32.v y == get_bitfield (U32.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #32 (U32.v x) (U32.v lo) (U32.v hi); (x `U32.shift_left` (32ul `U32.sub` hi)) `U32.shift_right` ((32ul `U32.sub` hi) `U32.add` lo) #push-options "--z3rlimit 16" inline_for_extraction let set_bitfield_gen32 (x: U32.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 32}) (v: U32.t { U32.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U32.t { U32.v y == set_bitfield (U32.v x) (U32.v lo) (U32.v hi) (U32.v v) }) = bitfield_mask_eq_2 32 (U32.v lo) (U32.v hi); (x `U32.logand` U32.lognot (((U32.lognot 0ul) `U32.shift_right` (32ul `U32.sub` (hi `U32.sub` lo))) `U32.shift_left` lo)) `U32.logor` (v `U32.shift_left` lo) #pop-options (* Instantiate to UInt16 *) inline_for_extraction let bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == bitfield_mask 16 lo hi }) = if lo = hi then 0us else begin bitfield_mask_eq_2 16 lo hi; (U16.lognot 0us `U16.shift_right` (16ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U16.shift_left` U32.uint_to_t lo end inline_for_extraction let u16_shift_right (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_right` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_right` amount inline_for_extraction let get_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) lo hi }) = (x `U16.logand` bitfield_mask16 lo hi) `u16_shift_right` (U32.uint_to_t lo) inline_for_extraction let not_bitfield_mask16 (lo: nat) (hi: nat { lo <= hi /\ hi <= 16 }) : Tot (x: U16.t { U16.v x == not_bitfield_mask 16 lo hi }) = U16.lognot (bitfield_mask16 lo hi) inline_for_extraction let u16_shift_left (x: U16.t) (amount: U32.t { U32.v amount <= 16 }) : Tot (y: U16.t { U16.v y == U16.v x `U.shift_left` U32.v amount }) = if amount = 16ul then 0us else x `U16.shift_left` amount inline_for_extraction let set_bitfield16 (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) lo hi (U16.v v) }) = (x `U16.logand` not_bitfield_mask16 lo hi) `U16.logor` (v `u16_shift_left` U32.uint_to_t lo) inline_for_extraction let bitfield_eq16_lhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) : Tot U16.t = x `U16.logand` bitfield_mask16 lo hi inline_for_extraction let bitfield_eq16_rhs (x: U16.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 16}) (v: U16.t { U16.v v < pow2 (hi - lo) }) : Tot (y: U16.t { bitfield_eq16_lhs x lo hi == y <==> (get_bitfield16 x lo hi <: U16.t) == v }) = [@inline_let] let _ = bitfield_eq_shift (U16.v x) lo hi (U16.v v) in v `u16_shift_left` U32.uint_to_t lo inline_for_extraction let get_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) : Tot (y: U16.t { U16.v y == get_bitfield (U16.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #16 (U16.v x) (U32.v lo) (U32.v hi); (* avoid integer promotion again *) let bf : U16.t = x `U16.shift_left` (16ul `U32.sub` hi) in bf `U16.shift_right` ((16ul `U32.sub` hi) `U32.add` lo) inline_for_extraction let set_bitfield_gen16 (x: U16.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 16}) (v: U16.t { U16.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U16.t { U16.v y == set_bitfield (U16.v x) (U32.v lo) (U32.v hi) (U16.v v) }) = bitfield_mask_eq_2 16 (U32.v lo) (U32.v hi); (x `U16.logand` U16.lognot (((U16.lognot 0us) `U16.shift_right` (16ul `U32.sub` (hi `U32.sub` lo))) `U16.shift_left` lo)) `U16.logor` (v `U16.shift_left` lo) inline_for_extraction let bitfield_mask8 (lo: nat) (hi: nat { lo <= hi /\ hi <= 8 }) : Tot (x: U8.t { U8.v x == bitfield_mask 8 lo hi }) = if lo = hi then 0uy else begin bitfield_mask_eq_2 8 lo hi; (U8.lognot 0uy `U8.shift_right` (8ul `U32.sub` (U32.uint_to_t (hi - lo)))) `U8.shift_left` U32.uint_to_t lo end inline_for_extraction let u8_shift_right (x: U8.t) (amount: U32.t { U32.v amount <= 8 }) : Tot (y: U8.t { U8.v y == U8.v x `U.shift_right` U32.v amount }) = let y = if amount = 8ul then 0uy else x `U8.shift_right` amount in y // inline_for_extraction // no, because of https://github.com/FStarLang/karamel/issues/102 let get_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) : Tot (y: U8.t { U8.v y == get_bitfield (U8.v x) (U32.v lo) (U32.v hi) }) = get_bitfield_eq_2 #8 (U8.v x) (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op1 = x `U8.shift_left` (8ul `U32.sub` hi) in let op2 = op1 `U8.shift_right` ((8ul `U32.sub` hi) `U32.add` lo) in op2 // inline_for_extraction // no, same let set_bitfield_gen8 (x: U8.t) (lo: U32.t) (hi: U32.t {U32.v lo < U32.v hi /\ U32.v hi <= 8}) (v: U8.t { U8.v v < pow2 (U32.v hi - U32.v lo) }) : Tot (y: U8.t { U8.v y == set_bitfield (U8.v x) (U32.v lo) (U32.v hi) (U8.v v) }) = bitfield_mask_eq_2 8 (U32.v lo) (U32.v hi); (* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *) let op0 = (U8.lognot 0uy) in let op1 = op0 `U8.shift_right` (8ul `U32.sub` (hi `U32.sub` lo)) in let op2 = op1 `U8.shift_left` lo in let op3 = U8.lognot op2 in let op4 = x `U8.logand` op3 in let op5 = v `U8.shift_left` lo in let op6 = op4 `U8.logor` op5 in op6 inline_for_extraction let get_bitfield8 (x: U8.t) (lo: nat) (hi: nat {lo <= hi /\ hi <= 8})
false
false
LowParse.BitFields.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 get_bitfield8 (x: U8.t) (lo: nat) (hi: nat{lo <= hi /\ hi <= 8}) : Tot (y: U8.t{U8.v y == get_bitfield (U8.v x) lo hi})
[]
LowParse.BitFields.get_bitfield8
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> lo: Prims.nat -> hi: Prims.nat{lo <= hi /\ hi <= 8} -> y: FStar.UInt8.t{FStar.UInt8.v y == LowParse.BitFields.get_bitfield (FStar.UInt8.v x) lo hi}
{ "end_col": 59, "end_line": 1160, "start_col": 2, "start_line": 1159 }
FStar.Pervasives.Lemma
val get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi ))
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "LowParse", "short_module": null }, { "abbrev": false, "full_module": "LowParse", "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 get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) = eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then begin if i < mi - lo then begin nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i end else begin nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi) end end )
val get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi )) let get_bitfield_partition_2_gen (#tot: pos) (lo mi: nat) (hi: nat{lo <= mi /\ mi <= hi /\ hi <= tot}) (x y: U.uint_t tot) : Lemma (requires (get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi)) (ensures (get_bitfield x lo hi == get_bitfield y lo hi)) =
false
null
true
eq_nth (get_bitfield x lo hi) (get_bitfield y lo hi) (fun i -> let a = nth (get_bitfield x lo hi) i in let b = nth (get_bitfield y lo hi) i in nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i; if i < hi - lo then if i < mi - lo then (nth_get_bitfield x lo mi i; nth_get_bitfield y lo mi i) else (nth_get_bitfield x mi hi (i + lo - mi); nth_get_bitfield y mi hi (i + lo - mi)))
{ "checked_file": "LowParse.BitFields.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.BitFields.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt.uint_t", "LowParse.BitFields.eq_nth", "LowParse.BitFields.get_bitfield", "Prims.op_LessThan", "Prims.op_Subtraction", "LowParse.BitFields.nth_get_bitfield", "Prims.unit", "Prims.bool", "Prims.op_Addition", "LowParse.BitFields.nth", "Prims.eq2", "LowParse.BitFields.ubitfield", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.BitFields module U = FStar.UInt module M = LowParse.Math open FStar.Mul inline_for_extraction let bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (U.uint_t tot) = [@inline_let] let _ = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo in normalize_term ((pow2 (hi - lo) - 1) * pow2 lo) let bitfield_mask_eq (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma ( 0 <= pow2 (hi - lo) - 1 /\ pow2 (hi - lo) - 1 < pow2 tot /\ bitfield_mask tot lo hi == U.shift_left #tot (pow2 (hi - lo) - 1) lo ) = M.pow2_le_compat tot (hi - lo); U.shift_left_value_lemma #tot (pow2 (hi - lo) - 1) lo; M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo; M.lemma_mult_nat (pow2 (hi - lo) - 1) (pow2 lo); M.lemma_mult_lt' (pow2 lo) (pow2 (hi - lo) - 1) (pow2 (hi - lo)); M.swap_mul (pow2 (hi - lo)) (pow2 lo); M.swap_mul (pow2 (hi - lo) - 1) (pow2 lo); M.modulo_lemma ((pow2 (hi - lo) - 1) * pow2 lo) (pow2 tot) (* Cf. U.index_to_vec_ones; WHY WHY WHY is it private? *) val nth_pow2_minus_one' : #n:pos -> m:nat{m <= n} -> i:nat{i < n} -> Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (i < n - m ==> U.nth #n (pow2 m - 1) i == false) /\ (n - m <= i ==> U.nth #n (pow2 m - 1) i == true))) let rec nth_pow2_minus_one' #n m i = let a = pow2 m - 1 in M.pow2_le_compat n m; if m = 0 then U.one_to_vec_lemma #n i else if m = n then U.ones_to_vec_lemma #n i else if i = n - 1 then () else nth_pow2_minus_one' #(n - 1) (m - 1) i (* Rephrasing with a more natural nth *) let nth (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Tot bool = U.nth a (n - 1 - i) let eq_nth (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (f: ( (i: nat { i < n }) -> Lemma (nth a i == nth b i) )) : Lemma (a == b) = let g (i: nat { i < n }) : Lemma (U.nth a i == U.nth b i) = f (n - 1 - i) in Classical.forall_intro g; U.nth_lemma a b let nth_pow2_minus_one (#n:pos) (m:nat{m <= n}) (i:nat{i < n}) : Lemma (requires True) (ensures (pow2 m <= pow2 n /\ (nth #n (pow2 m - 1) i == (i < m)))) = nth_pow2_minus_one' #n m (n - 1 - i) let nth_shift_left (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_left a s) i == (s <= i && nth a (i - s))) = () let nth_shift_right (#n: pos) (a: U.uint_t n) (s: nat) (i: nat {i < n}) : Lemma (nth (U.shift_right a s) i == (i + s < n && nth a (i + s))) = () let nth_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (bitfield_mask tot lo hi) i == (lo <= i && i < hi)) = bitfield_mask_eq tot lo hi; nth_shift_left #tot (pow2 (hi - lo) - 1) lo i; if i < lo then () else begin nth_pow2_minus_one #tot (hi - lo) (i - lo) end let get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (U.uint_t tot) = (x `U.logand` bitfield_mask tot lo hi) `U.shift_right` lo let nth_logand (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logand` b) i == (nth a i && nth b i)) = () let nth_logor (#n: pos) (a b: U.uint_t n) (i: nat {i < n}) : Lemma (nth (a `U.logor` b) i == (nth a i || nth b i)) = () let nth_lognot (#n: pos) (a: U.uint_t n) (i: nat {i < n}) : Lemma (nth (U.lognot a) i == not (nth a i)) = () let nth_get_bitfield_raw (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield_raw x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_shift_right (x `U.logand` bitfield_mask tot lo hi) lo i; if i + lo < tot then begin nth_logand x (bitfield_mask tot lo hi) (i + lo); nth_bitfield_mask tot lo hi (i + lo) end else () let get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (let y = get_bitfield_raw x lo hi in pow2 (hi - lo) - 1 < pow2 tot /\ y == y `U.logand` (pow2 (hi - lo) - 1) ) = nth_pow2_minus_one #tot (hi - lo) 0; let y = get_bitfield_raw x lo hi in eq_nth y (y `U.logand` (pow2 (hi - lo) - 1)) (fun i -> nth_get_bitfield_raw x lo hi i; nth_pow2_minus_one #tot (hi - lo) i; nth_logand y (pow2 (hi - lo) - 1) i ) #push-options "--z3rlimit 16" let logand_mask (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) : Lemma (pow2 m <= pow2 n /\ U.logand a (pow2 m - 1) == a % pow2 m) = M.pow2_le_compat n m; if m = 0 then begin U.logand_lemma_1 a end else if m = n then begin U.logand_lemma_2 a; M.modulo_lemma a (pow2 m) end else begin U.logand_mask a m end #pop-options let nth_le_pow2_m (#n: pos) (a: U.uint_t n) (m: nat {m <= n}) (i: nat {i < n}) : Lemma (requires (a < pow2 m /\ m <= i)) (ensures (nth a i == false)) = logand_mask a m; M.modulo_lemma a (pow2 m); nth_pow2_minus_one #n m i; nth_logand a (pow2 m - 1) i let get_bitfield_raw_bounded (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield_raw x lo hi < pow2 (hi - lo)) = get_bitfield_raw_eq_logand_pow2_hi_lo_minus_one x lo hi; logand_mask (get_bitfield_raw x lo hi) (hi - lo); M.lemma_mod_lt x (pow2 (hi - lo)) let get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Tot (ubitfield tot (hi - lo)) = get_bitfield_raw_bounded x lo hi; get_bitfield_raw x lo hi let nth_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) (i: nat {i < tot}) : Lemma (nth (get_bitfield x lo hi) i == (i < hi - lo && nth x (i + lo))) = nth_get_bitfield_raw x lo hi i let get_bitfield_logor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logor` y) lo hi) (get_bitfield x lo hi `U.logor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) let get_bitfield_logxor (#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot}) : Lemma (get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) = eq_nth (get_bitfield (x `U.logxor` y) lo hi) (get_bitfield x lo hi `U.logxor` get_bitfield y lo hi) (fun i -> nth_get_bitfield (x `U.logxor` y) lo hi i; nth_get_bitfield x lo hi i; nth_get_bitfield y lo hi i ) #push-options "--z3rlimit 16" let logor_disjoint (#n: pos) (a: U.uint_t n) (b: U.uint_t n) (m: nat {m <= n}) : Lemma (requires ( a % pow2 m == 0 /\ b < pow2 m )) (ensures (U.logor #n a b == a + b)) = if m = 0 then U.logor_lemma_1 a else if m = n then begin M.modulo_lemma a (pow2 n); U.logor_commutative a b; U.logor_lemma_1 b end else U.logor_disjoint a b m #pop-options let bitfield_mask_mod_pow2_lo (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (m: nat {m <= lo}) : Lemma (bitfield_mask tot lo hi % pow2 m == 0) = M.pow2_multiplication_modulo_lemma_1 (pow2 (hi - lo) - 1) m lo let bitfield_mask_lt_pow2_hi (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (bitfield_mask tot lo hi < pow2 hi) = M.pow2_le_compat tot hi; M.pow2_plus (hi - lo) lo inline_for_extraction let not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Tot (x: U.uint_t tot {x == U.lognot (bitfield_mask tot lo hi)}) = [@inline_let] let a = bitfield_mask tot hi tot in [@inline_let] let b = bitfield_mask tot 0 lo in [@inline_let] let _ = bitfield_mask_mod_pow2_lo tot hi tot lo; bitfield_mask_lt_pow2_hi tot 0 lo; logor_disjoint a b lo; eq_nth (a `U.logor` b) (U.lognot (bitfield_mask tot lo hi)) (fun i -> nth_bitfield_mask tot hi tot i; nth_bitfield_mask tot 0 lo i; nth_bitfield_mask tot lo hi i ) in normalize_term (a + b) let nth_not_bitfield_mask (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (i: nat {i < tot}) : Lemma (nth (not_bitfield_mask tot lo hi) i == (i < lo || hi <= i)) = nth_lognot (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i let set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Tot (U.uint_t tot) = (x `U.logand` not_bitfield_mask tot lo hi) `U.logor` (v `U.shift_left` lo) let nth_set_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (i: nat {i < tot}) : Lemma (nth (set_bitfield x lo hi v) i == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) = let y = nth (set_bitfield x lo hi v) i in nth_logor (x `U.logand` not_bitfield_mask tot lo hi) (v `U.shift_left` lo) i; assert (y == (nth (x `U.logand` not_bitfield_mask tot lo hi) i || nth (v `U.shift_left` lo) i)); nth_logand x (not_bitfield_mask tot lo hi) i; assert (y == ((nth x i && nth (not_bitfield_mask tot lo hi) i) || nth (v `U.shift_left` lo) i)); nth_not_bitfield_mask tot lo hi i; assert (y == ((nth x i && (i < lo || hi <= i)) || nth (v `U.shift_left` lo) i)); nth_shift_left v lo i; assert (y == ((nth x i && (i < lo || hi <= i)) || (lo <= i && nth v (i - lo)))); if (lo <= i && i < hi) then assert (y == nth v (i - lo)) else if (i < hi) then assert (y == nth x i) else begin nth_le_pow2_m v (hi - lo) (i - lo); assert (y == nth x i) end; assert (y == (if lo <= i && i < hi then nth v (i - lo) else nth x i)) #push-options "--z3rlimit 32" let get_bitfield_set_bitfield_same (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield (set_bitfield x lo hi v) lo hi == v) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo hi) v (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo hi i; if i < hi - lo then begin nth_set_bitfield x lo hi v (i + lo) end else nth_le_pow2_m v (hi - lo) i ) #pop-options let get_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi')) = eq_nth (get_bitfield (set_bitfield x lo hi v) lo' hi') (get_bitfield x lo' hi') (fun i -> nth_get_bitfield (set_bitfield x lo hi v) lo' hi' i; nth_get_bitfield x lo' hi' i; if i < hi' - lo' then begin nth_set_bitfield x lo hi v (i + lo') end ) let set_bitfield_set_bitfield_same_gen (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield x lo' hi' v') (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_set_bitfield_other (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) (lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo')) : Lemma (requires (hi' <= lo \/ hi <= lo')) (ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v)) = eq_nth (set_bitfield (set_bitfield x lo hi v) lo' hi' v') (set_bitfield (set_bitfield x lo' hi' v') lo hi v) (fun i -> nth_set_bitfield (set_bitfield x lo hi v) lo' hi' v' i; nth_set_bitfield x lo hi v i; nth_set_bitfield (set_bitfield x lo' hi' v') lo hi v i; nth_set_bitfield x lo' hi' v' i ) let set_bitfield_full (#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot) : Lemma (set_bitfield x 0 tot y == y) = eq_nth (set_bitfield x 0 tot y) y (fun i -> nth_set_bitfield x 0 tot y i ) let set_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0) : Lemma (set_bitfield x i i y == x) = eq_nth (set_bitfield x i i y) x (fun j -> nth_set_bitfield x i i y j ) let nth_zero (tot: pos) (i: nat {i < tot}) : Lemma (nth #tot 0 i == false) = U.zero_nth_lemma #tot i let get_bitfield_zero (tot: pos) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield #tot 0 lo hi == 0) = eq_nth (get_bitfield #tot 0 lo hi) 0 (fun i -> nth_zero tot i; nth_get_bitfield #tot 0 lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) let get_bitfield_full (#tot: pos) (x: U.uint_t tot) : Lemma (get_bitfield x 0 tot == x) = eq_nth (get_bitfield x 0 tot) x (fun i -> nth_get_bitfield x 0 tot i ) let get_bitfield_empty (#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) : Lemma (get_bitfield x i i == 0) = eq_nth (get_bitfield x i i) 0 (fun j -> nth_get_bitfield x i i j; nth_zero tot j ) let lt_pow2_get_bitfield_hi (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (x < pow2 mi)) (ensures (get_bitfield x mi tot == 0)) = if mi = 0 then get_bitfield_zero tot mi tot else if mi < tot then begin M.modulo_lemma x (pow2 mi); U.logand_mask x mi; eq_nth (get_bitfield x mi tot) 0 (fun i -> nth_zero tot i; nth_get_bitfield x mi tot i; nth_get_bitfield (x `U.logand` (pow2 mi - 1)) mi tot i; nth_pow2_minus_one #tot mi i ) end let get_bitfield_hi_lt_pow2 (#tot: pos) (x: U.uint_t tot) (mi: nat {mi <= tot}) : Lemma (requires (get_bitfield x mi tot == 0)) (ensures (x < pow2 mi)) = if mi = 0 then get_bitfield_full x else if mi < tot then begin M.pow2_le_compat tot mi; eq_nth x (x `U.logand` (pow2 mi - 1)) (fun i -> nth_pow2_minus_one #tot mi i; if mi <= i then begin nth_get_bitfield x mi tot (i - mi); nth_zero tot (i - mi) end ); U.logand_mask x mi; M.lemma_mod_lt x (pow2 mi) end let get_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo }) : Lemma (get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi')) = eq_nth (get_bitfield (get_bitfield x lo hi) lo' hi') (get_bitfield x (lo + lo') (lo + hi')) (fun i -> nth_get_bitfield (get_bitfield x lo hi) lo' hi' i; nth_get_bitfield x (lo + lo') (lo + hi') i ; if i < hi' - lo' then nth_get_bitfield x lo hi (i + lo') ) #push-options "--z3rlimit_factor 2" let get_bitfield_zero_inner (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi }) : Lemma (ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0)) = let f () : Lemma (requires (get_bitfield x lo hi == 0)) (ensures (get_bitfield x lo' hi' == 0)) = eq_nth (get_bitfield x lo' hi') 0 (fun i -> nth_get_bitfield x lo' hi' i; nth_zero tot i; if (i < hi' - lo') then begin nth_get_bitfield x lo hi (i + lo' - lo); nth_zero tot (i + lo'); nth_zero tot (i + lo' - lo) end ) in Classical.move_requires f () #pop-options #push-options "--z3rlimit 32" let bitfield_is_zero (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (get_bitfield x lo hi == 0 <==> x `U.logand` bitfield_mask tot lo hi == 0) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let f () : Lemma (requires (y == 0)) (ensures (z == 0)) = eq_nth z 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if i < hi - lo then nth_zero tot (i + lo) ) in let g () : Lemma (requires (z == 0)) (ensures (y == 0)) = eq_nth y 0 (fun i -> nth_zero tot i; nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; if lo <= i && i < hi then begin nth_get_bitfield x lo hi (i - lo); nth_zero tot (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let bitfield_eq_shift (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo)) : Lemma (get_bitfield x lo hi == v <==> x `U.logand` bitfield_mask tot lo hi == v `U.shift_left` lo) = let y = x `U.logand` bitfield_mask tot lo hi in let z = get_bitfield x lo hi in let w = v `U.shift_left` lo in let f () : Lemma (requires (y == w)) (ensures (z == v)) = eq_nth z v (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_get_bitfield x lo hi i; if hi - lo <= i then nth_le_pow2_m v (hi - lo) i else nth_shift_left v lo (i + lo) ) in let g () : Lemma (requires (z == v)) (ensures (y == w)) = eq_nth y w (fun i -> nth_logand x (bitfield_mask tot lo hi) i; nth_bitfield_mask tot lo hi i; nth_shift_left v lo i; if hi <= i then nth_le_pow2_m v (hi - lo) (i - lo) else if lo <= i then begin nth_get_bitfield x lo hi (i - lo) end ) in Classical.move_requires f (); Classical.move_requires g () #pop-options #push-options "--z3rlimit 16" let set_bitfield_get_bitfield (#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) : Lemma (set_bitfield x lo hi (get_bitfield x lo hi) == x) = eq_nth (set_bitfield x lo hi (get_bitfield x lo hi)) x (fun i -> nth_set_bitfield x lo hi (get_bitfield x lo hi) i; if lo <= i && i < hi then nth_get_bitfield x lo hi (i - lo) ) #pop-options #push-options "--z3rlimit 16" let get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi
false
false
LowParse.BitFields.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 get_bitfield_partition_2_gen (#tot: pos) (lo: nat) (mi: nat) (hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot }) (x y: U.uint_t tot) : Lemma (requires ( get_bitfield x lo mi == get_bitfield y lo mi /\ get_bitfield x mi hi == get_bitfield y mi hi )) (ensures ( get_bitfield x lo hi == get_bitfield y lo hi ))
[]
LowParse.BitFields.get_bitfield_partition_2_gen
{ "file_name": "src/lowparse/LowParse.BitFields.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
lo: Prims.nat -> mi: Prims.nat -> hi: Prims.nat{lo <= mi /\ mi <= hi /\ hi <= tot} -> x: FStar.UInt.uint_t tot -> y: FStar.UInt.uint_t tot -> FStar.Pervasives.Lemma (requires LowParse.BitFields.get_bitfield x lo mi == LowParse.BitFields.get_bitfield y lo mi /\ LowParse.BitFields.get_bitfield x mi hi == LowParse.BitFields.get_bitfield y mi hi) (ensures LowParse.BitFields.get_bitfield x lo hi == LowParse.BitFields.get_bitfield y lo hi)
{ "end_col": 3, "end_line": 660, "start_col": 2, "start_line": 644 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Lib", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "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 fill_elems_st = #t:Type0 -> #a:Type0 -> h0:mem -> n:size_t -> output:lbuffer t n -> refl:(mem -> i:size_nat{i <= v n} -> GTot a) -> footprint:(i:size_nat{i <= v n} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < v n} -> a -> a & t)) -> impl:(i:size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o))
let fill_elems_st =
false
null
false
#t: Type0 -> #a: Type0 -> h0: mem -> n: size_t -> output: lbuffer t n -> refl: (mem -> i: size_nat{i <= v n} -> GTot a) -> footprint: (i: size_nat{i <= v n} -> GTot (l: B.loc { B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l })) -> spec: (mem -> GTot (i: size_nat{i < v n} -> a -> a & t)) -> impl: (i: size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ (footprint (v i + 1)) `B.loc_includes` (footprint (v i)) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o))
{ "checked_file": "Hacl.Impl.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Lib.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.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.Lib.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_disjoint", "Lib.Buffer.loc", "Lib.Buffer.MUT", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.op_LessThan", "FStar.Pervasives.Native.tuple2", "Prims.unit", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.gsub", "FStar.UInt32.__uint_to_t", "Prims.eq2", "Prims.op_Addition", "Lib.Sequence.index", "Lib.Buffer.as_seq", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.live", "Lib.Sequence.seq", "Prims.nat", "Lib.Sequence.length", "Prims.l_or", "FStar.Seq.Base.length", "Prims.logical", "Hacl.Spec.Lib.generate_elems" ]
[]
module Hacl.Impl.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module Loops = Lib.LoopCombinators module S = Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract
false
true
Hacl.Impl.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 fill_elems_st : Type
[]
Hacl.Impl.Lib.fill_elems_st
{ "file_name": "code/bignum/Hacl.Impl.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type
{ "end_col": 57, "end_line": 44, "start_col": 2, "start_line": 21 }
FStar.HyperStack.ST.Stack
val update_sub_f_carry: #a:Type -> #b:Type -> #len:size_t -> h0:mem -> buf:lbuffer a len -> start:size_t -> n:size_t{v start + v n <= v len} -> spec:(mem -> GTot (b & Seq.lseq a (v n))) -> f:(unit -> Stack b (requires fun h -> h0 == h) (ensures fun _ r h1 -> (let b = gsub buf start n in modifies (loc b) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 b == res)))) -> Stack b (requires fun h -> h0 == h /\ live h buf) (ensures fun h0 r h1 -> modifies (loc buf) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 buf == LSeq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) res))
[ { "abbrev": true, "full_module": "Hacl.Spec.Lib", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "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_sub_f_carry #a #b #len h0 buf start n spec f = let tmp = sub buf start n in let h0 = ST.get () in let r = f () in let h1 = ST.get () in assert (v (len -! (start +! n)) == v len - v (start +! n)); B.modifies_buffer_elim (B.gsub #a buf 0ul start) (loc tmp) h0 h1; B.modifies_buffer_elim (B.gsub #a buf (start +! n) (len -! (start +! n))) (loc tmp) h0 h1; LSeq.lemma_update_sub (as_seq h0 buf) (v start) (v n) (snd (spec h0)) (as_seq h1 buf); r
val update_sub_f_carry: #a:Type -> #b:Type -> #len:size_t -> h0:mem -> buf:lbuffer a len -> start:size_t -> n:size_t{v start + v n <= v len} -> spec:(mem -> GTot (b & Seq.lseq a (v n))) -> f:(unit -> Stack b (requires fun h -> h0 == h) (ensures fun _ r h1 -> (let b = gsub buf start n in modifies (loc b) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 b == res)))) -> Stack b (requires fun h -> h0 == h /\ live h buf) (ensures fun h0 r h1 -> modifies (loc buf) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 buf == LSeq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) res)) let update_sub_f_carry #a #b #len h0 buf start n spec f =
true
null
false
let tmp = sub buf start n in let h0 = ST.get () in let r = f () in let h1 = ST.get () in assert (v (len -! (start +! n)) == v len - v (start +! n)); B.modifies_buffer_elim (B.gsub #a buf 0ul start) (loc tmp) h0 h1; B.modifies_buffer_elim (B.gsub #a buf (start +! n) (len -! (start +! n))) (loc tmp) h0 h1; LSeq.lemma_update_sub (as_seq h0 buf) (v start) (v n) (snd (spec h0)) (as_seq h1 buf); r
{ "checked_file": "Hacl.Impl.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Lib.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.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.Lib.fst" }
[]
[ "Lib.IntTypes.size_t", "FStar.Monotonic.HyperStack.mem", "Lib.Buffer.lbuffer", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.lseq", "Prims.unit", "Prims.eq2", "Prims.l_and", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Lib.Buffer.MUT", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Lib.Buffer.as_seq", "Prims.logical", "Lib.Buffer.lbuffer_t", "Lib.Buffer.gsub", "Lib.Sequence.lemma_update_sub", "FStar.Pervasives.Native.snd", "LowStar.Monotonic.Buffer.modifies_buffer_elim", "LowStar.Buffer.trivial_preorder", "LowStar.Buffer.gsub", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.op_Subtraction_Bang", "FStar.UInt32.__uint_to_t", "Prims._assert", "Prims.int", "Prims.op_Subtraction", "FStar.HyperStack.ST.get", "Lib.Buffer.sub" ]
[]
module Hacl.Impl.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module Loops = Lib.LoopCombinators module S = Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let fill_elems_st = #t:Type0 -> #a:Type0 -> h0:mem -> n:size_t -> output:lbuffer t n -> refl:(mem -> i:size_nat{i <= v n} -> GTot a) -> footprint:(i:size_nat{i <= v n} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < v n} -> a -> a & t)) -> impl:(i:size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o)) inline_for_extraction noextract val fill_elems : fill_elems_st let fill_elems #t #a h0 n output refl footprint spec impl = [@inline_let] let refl' h (i:nat{i <= v n}) : GTot (S.generate_elem_a t a (v n) i) = refl h i, as_seq h (gsub output 0ul (size i)) in [@inline_let] let footprint' i = footprint i |+| loc (gsub output 0ul (size i)) in [@inline_let] let spec' h0 = S.generate_elem_f (v n) (spec h0) in let h0 = ST.get () in loop h0 n (S.generate_elem_a t a (v n)) refl' footprint' spec' (fun i -> Loops.unfold_repeat_gen (v n) (S.generate_elem_a t a (v n)) (spec' h0) (refl' h0 0) (v i); impl i; let h = ST.get() in FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i) ); let h1 = ST.get () in assert (refl' h1 (v n) == Loops.repeat_gen (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl' h0 0)) inline_for_extraction noextract val fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o)) let fill_blocks4 #t #a h0 n4 output refl footprint spec impl = fill_blocks h0 4ul n4 output (Loops.fixed_a a) (fun h i -> refl h (4 * i)) (fun i -> footprint (4 * i)) (fun h0 -> S.generate_blocks4_f #t #a (v n4) (spec h0)) (fun i -> let h1 = ST.get () in impl (4ul *! i); impl (4ul *! i +! 1ul); impl (4ul *! i +! 2ul); impl (4ul *! i +! 3ul); let h2 = ST.get () in assert ( let c0, e0 = spec h0 (4 * v i) (refl h1 (4 * v i)) in let c1, e1 = spec h0 (4 * v i + 1) c0 in let c2, e2 = spec h0 (4 * v i + 2) c1 in let c3, e3 = spec h0 (4 * v i + 3) c2 in let res = LSeq.create4 e0 e1 e2 e3 in LSeq.create4_lemma e0 e1 e2 e3; let res1 = LSeq.sub (as_seq h2 output) (4 * v i) 4 in refl h2 (4 * v i + 4) == c3 /\ (LSeq.eq_intro res res1; res1 `LSeq.equal` res)) ) inline_for_extraction noextract val fill_elems4: fill_elems_st let fill_elems4 #t #a h0 n output refl footprint spec impl = [@inline_let] let k = n /. 4ul in let tmp = sub output 0ul (4ul *! k) in fill_blocks4 #t #a h0 k tmp refl footprint spec (fun i -> impl i); let h1 = ST.get () in assert (4 * v k + v (n -! 4ul *! k) = v n); B.modifies_buffer_elim (B.gsub #t output (4ul *! k) (n -! 4ul *! k)) (footprint (4 * v k) |+| loc tmp) h0 h1; assert (modifies (footprint (4 * v k) |+| loc (gsub output 0ul (4ul *! k))) h0 h1); let inv (h:mem) (i:nat{4 * v k <= i /\ i <= v n}) = modifies (footprint i |+| loc (gsub output 0ul (size i))) h0 h /\ (let (c, res) = Loops.repeat_right (v n / 4 * 4) i (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) in refl h i == c /\ as_seq h (gsub output 0ul (size i)) == res) in Loops.eq_repeat_right (v n / 4 * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))); Lib.Loops.for (k *! 4ul) n inv (fun i -> impl i; let h = ST.get () in assert (v (i +! 1ul) = v i + 1); FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i); Loops.unfold_repeat_right (v n / 4 * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) (v i) ); S.lemma_generate_elems4 (v n) (v n) (spec h0) (refl h0 0) inline_for_extraction noextract val lemma_eq_disjoint: #a1:Type -> #a2:Type -> #a3:Type -> clen1:size_t -> clen2:size_t -> clen3:size_t -> b1:lbuffer a1 clen1 -> b2:lbuffer a2 clen2 -> b3:lbuffer a3 clen3 -> n:size_t{v n < v clen2 /\ v n < v clen1} -> h0:mem -> h1:mem -> Lemma (requires live h0 b1 /\ live h0 b2 /\ live h0 b3 /\ eq_or_disjoint b1 b2 /\ disjoint b1 b3 /\ disjoint b2 b3 /\ modifies (loc (gsub b1 0ul n) |+| loc b3) h0 h1) (ensures (let b2s = gsub b2 n (clen2 -! n) in as_seq h0 b2s == as_seq h1 b2s /\ Seq.index (as_seq h0 b2) (v n) == Seq.index (as_seq h1 b2) (v n))) let lemma_eq_disjoint #a1 #a2 #a3 clen1 clen2 clen3 b1 b2 b3 n h0 h1 = let b1s = gsub b1 0ul n in let b2s = gsub b2 0ul n in assert (modifies (loc b1s |+| loc b3) h0 h1); assert (disjoint b1 b2 ==> Seq.equal (as_seq h0 b2) (as_seq h1 b2)); assert (disjoint b1 b2 ==> Seq.equal (as_seq h0 b2s) (as_seq h1 b2s)); assert (Seq.index (as_seq h1 b2) (v n) == Seq.index (as_seq h1 (gsub b2 n (clen2 -! n))) 0) inline_for_extraction noextract val update_sub_f_carry: #a:Type -> #b:Type -> #len:size_t -> h0:mem -> buf:lbuffer a len -> start:size_t -> n:size_t{v start + v n <= v len} -> spec:(mem -> GTot (b & Seq.lseq a (v n))) -> f:(unit -> Stack b (requires fun h -> h0 == h) (ensures fun _ r h1 -> (let b = gsub buf start n in modifies (loc b) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 b == res)))) -> Stack b (requires fun h -> h0 == h /\ live h buf) (ensures fun h0 r h1 -> modifies (loc buf) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 buf == LSeq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) res))
false
false
Hacl.Impl.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 update_sub_f_carry: #a:Type -> #b:Type -> #len:size_t -> h0:mem -> buf:lbuffer a len -> start:size_t -> n:size_t{v start + v n <= v len} -> spec:(mem -> GTot (b & Seq.lseq a (v n))) -> f:(unit -> Stack b (requires fun h -> h0 == h) (ensures fun _ r h1 -> (let b = gsub buf start n in modifies (loc b) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 b == res)))) -> Stack b (requires fun h -> h0 == h /\ live h buf) (ensures fun h0 r h1 -> modifies (loc buf) h0 h1 /\ (let (c, res) = spec h0 in r == c /\ as_seq h1 buf == LSeq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) res))
[]
Hacl.Impl.Lib.update_sub_f_carry
{ "file_name": "code/bignum/Hacl.Impl.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> buf: Lib.Buffer.lbuffer a len -> start: Lib.IntTypes.size_t -> n: Lib.IntTypes.size_t{Lib.IntTypes.v start + Lib.IntTypes.v n <= Lib.IntTypes.v len} -> spec: (_: FStar.Monotonic.HyperStack.mem -> Prims.GTot (b * FStar.Seq.Properties.lseq a (Lib.IntTypes.v n))) -> f: (_: Prims.unit -> FStar.HyperStack.ST.Stack b) -> FStar.HyperStack.ST.Stack b
{ "end_col": 3, "end_line": 218, "start_col": 57, "start_line": 209 }
FStar.Pervasives.Lemma
val lemma_eq_disjoint: #a1:Type -> #a2:Type -> #a3:Type -> clen1:size_t -> clen2:size_t -> clen3:size_t -> b1:lbuffer a1 clen1 -> b2:lbuffer a2 clen2 -> b3:lbuffer a3 clen3 -> n:size_t{v n < v clen2 /\ v n < v clen1} -> h0:mem -> h1:mem -> Lemma (requires live h0 b1 /\ live h0 b2 /\ live h0 b3 /\ eq_or_disjoint b1 b2 /\ disjoint b1 b3 /\ disjoint b2 b3 /\ modifies (loc (gsub b1 0ul n) |+| loc b3) h0 h1) (ensures (let b2s = gsub b2 n (clen2 -! n) in as_seq h0 b2s == as_seq h1 b2s /\ Seq.index (as_seq h0 b2) (v n) == Seq.index (as_seq h1 b2) (v n)))
[ { "abbrev": true, "full_module": "Hacl.Spec.Lib", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "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_eq_disjoint #a1 #a2 #a3 clen1 clen2 clen3 b1 b2 b3 n h0 h1 = let b1s = gsub b1 0ul n in let b2s = gsub b2 0ul n in assert (modifies (loc b1s |+| loc b3) h0 h1); assert (disjoint b1 b2 ==> Seq.equal (as_seq h0 b2) (as_seq h1 b2)); assert (disjoint b1 b2 ==> Seq.equal (as_seq h0 b2s) (as_seq h1 b2s)); assert (Seq.index (as_seq h1 b2) (v n) == Seq.index (as_seq h1 (gsub b2 n (clen2 -! n))) 0)
val lemma_eq_disjoint: #a1:Type -> #a2:Type -> #a3:Type -> clen1:size_t -> clen2:size_t -> clen3:size_t -> b1:lbuffer a1 clen1 -> b2:lbuffer a2 clen2 -> b3:lbuffer a3 clen3 -> n:size_t{v n < v clen2 /\ v n < v clen1} -> h0:mem -> h1:mem -> Lemma (requires live h0 b1 /\ live h0 b2 /\ live h0 b3 /\ eq_or_disjoint b1 b2 /\ disjoint b1 b3 /\ disjoint b2 b3 /\ modifies (loc (gsub b1 0ul n) |+| loc b3) h0 h1) (ensures (let b2s = gsub b2 n (clen2 -! n) in as_seq h0 b2s == as_seq h1 b2s /\ Seq.index (as_seq h0 b2) (v n) == Seq.index (as_seq h1 b2) (v n))) let lemma_eq_disjoint #a1 #a2 #a3 clen1 clen2 clen3 b1 b2 b3 n h0 h1 =
false
null
true
let b1s = gsub b1 0ul n in let b2s = gsub b2 0ul n in assert (modifies (loc b1s |+| loc b3) h0 h1); assert (disjoint b1 b2 ==> Seq.equal (as_seq h0 b2) (as_seq h1 b2)); assert (disjoint b1 b2 ==> Seq.equal (as_seq h0 b2s) (as_seq h1 b2s)); assert (Seq.index (as_seq h1 b2) (v n) == Seq.index (as_seq h1 (gsub b2 n (clen2 -! n))) 0)
{ "checked_file": "Hacl.Impl.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Lib.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.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.Lib.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.Monotonic.HyperStack.mem", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.index", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.IntTypes.op_Subtraction_Bang", "Lib.Buffer.gsub", "Prims.unit", "Prims.l_imp", "Lib.Buffer.disjoint", "FStar.Seq.Base.equal", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.loc", "Lib.Buffer.lbuffer_t", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module Loops = Lib.LoopCombinators module S = Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let fill_elems_st = #t:Type0 -> #a:Type0 -> h0:mem -> n:size_t -> output:lbuffer t n -> refl:(mem -> i:size_nat{i <= v n} -> GTot a) -> footprint:(i:size_nat{i <= v n} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < v n} -> a -> a & t)) -> impl:(i:size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o)) inline_for_extraction noextract val fill_elems : fill_elems_st let fill_elems #t #a h0 n output refl footprint spec impl = [@inline_let] let refl' h (i:nat{i <= v n}) : GTot (S.generate_elem_a t a (v n) i) = refl h i, as_seq h (gsub output 0ul (size i)) in [@inline_let] let footprint' i = footprint i |+| loc (gsub output 0ul (size i)) in [@inline_let] let spec' h0 = S.generate_elem_f (v n) (spec h0) in let h0 = ST.get () in loop h0 n (S.generate_elem_a t a (v n)) refl' footprint' spec' (fun i -> Loops.unfold_repeat_gen (v n) (S.generate_elem_a t a (v n)) (spec' h0) (refl' h0 0) (v i); impl i; let h = ST.get() in FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i) ); let h1 = ST.get () in assert (refl' h1 (v n) == Loops.repeat_gen (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl' h0 0)) inline_for_extraction noextract val fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o)) let fill_blocks4 #t #a h0 n4 output refl footprint spec impl = fill_blocks h0 4ul n4 output (Loops.fixed_a a) (fun h i -> refl h (4 * i)) (fun i -> footprint (4 * i)) (fun h0 -> S.generate_blocks4_f #t #a (v n4) (spec h0)) (fun i -> let h1 = ST.get () in impl (4ul *! i); impl (4ul *! i +! 1ul); impl (4ul *! i +! 2ul); impl (4ul *! i +! 3ul); let h2 = ST.get () in assert ( let c0, e0 = spec h0 (4 * v i) (refl h1 (4 * v i)) in let c1, e1 = spec h0 (4 * v i + 1) c0 in let c2, e2 = spec h0 (4 * v i + 2) c1 in let c3, e3 = spec h0 (4 * v i + 3) c2 in let res = LSeq.create4 e0 e1 e2 e3 in LSeq.create4_lemma e0 e1 e2 e3; let res1 = LSeq.sub (as_seq h2 output) (4 * v i) 4 in refl h2 (4 * v i + 4) == c3 /\ (LSeq.eq_intro res res1; res1 `LSeq.equal` res)) ) inline_for_extraction noextract val fill_elems4: fill_elems_st let fill_elems4 #t #a h0 n output refl footprint spec impl = [@inline_let] let k = n /. 4ul in let tmp = sub output 0ul (4ul *! k) in fill_blocks4 #t #a h0 k tmp refl footprint spec (fun i -> impl i); let h1 = ST.get () in assert (4 * v k + v (n -! 4ul *! k) = v n); B.modifies_buffer_elim (B.gsub #t output (4ul *! k) (n -! 4ul *! k)) (footprint (4 * v k) |+| loc tmp) h0 h1; assert (modifies (footprint (4 * v k) |+| loc (gsub output 0ul (4ul *! k))) h0 h1); let inv (h:mem) (i:nat{4 * v k <= i /\ i <= v n}) = modifies (footprint i |+| loc (gsub output 0ul (size i))) h0 h /\ (let (c, res) = Loops.repeat_right (v n / 4 * 4) i (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) in refl h i == c /\ as_seq h (gsub output 0ul (size i)) == res) in Loops.eq_repeat_right (v n / 4 * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))); Lib.Loops.for (k *! 4ul) n inv (fun i -> impl i; let h = ST.get () in assert (v (i +! 1ul) = v i + 1); FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i); Loops.unfold_repeat_right (v n / 4 * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) (v i) ); S.lemma_generate_elems4 (v n) (v n) (spec h0) (refl h0 0) inline_for_extraction noextract val lemma_eq_disjoint: #a1:Type -> #a2:Type -> #a3:Type -> clen1:size_t -> clen2:size_t -> clen3:size_t -> b1:lbuffer a1 clen1 -> b2:lbuffer a2 clen2 -> b3:lbuffer a3 clen3 -> n:size_t{v n < v clen2 /\ v n < v clen1} -> h0:mem -> h1:mem -> Lemma (requires live h0 b1 /\ live h0 b2 /\ live h0 b3 /\ eq_or_disjoint b1 b2 /\ disjoint b1 b3 /\ disjoint b2 b3 /\ modifies (loc (gsub b1 0ul n) |+| loc b3) h0 h1) (ensures (let b2s = gsub b2 n (clen2 -! n) in as_seq h0 b2s == as_seq h1 b2s /\ Seq.index (as_seq h0 b2) (v n) == Seq.index (as_seq h1 b2) (v n)))
false
false
Hacl.Impl.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_eq_disjoint: #a1:Type -> #a2:Type -> #a3:Type -> clen1:size_t -> clen2:size_t -> clen3:size_t -> b1:lbuffer a1 clen1 -> b2:lbuffer a2 clen2 -> b3:lbuffer a3 clen3 -> n:size_t{v n < v clen2 /\ v n < v clen1} -> h0:mem -> h1:mem -> Lemma (requires live h0 b1 /\ live h0 b2 /\ live h0 b3 /\ eq_or_disjoint b1 b2 /\ disjoint b1 b3 /\ disjoint b2 b3 /\ modifies (loc (gsub b1 0ul n) |+| loc b3) h0 h1) (ensures (let b2s = gsub b2 n (clen2 -! n) in as_seq h0 b2s == as_seq h1 b2s /\ Seq.index (as_seq h0 b2) (v n) == Seq.index (as_seq h1 b2) (v n)))
[]
Hacl.Impl.Lib.lemma_eq_disjoint
{ "file_name": "code/bignum/Hacl.Impl.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
clen1: Lib.IntTypes.size_t -> clen2: Lib.IntTypes.size_t -> clen3: Lib.IntTypes.size_t -> b1: Lib.Buffer.lbuffer a1 clen1 -> b2: Lib.Buffer.lbuffer a2 clen2 -> b3: Lib.Buffer.lbuffer a3 clen3 -> n: Lib.IntTypes.size_t {Lib.IntTypes.v n < Lib.IntTypes.v clen2 /\ Lib.IntTypes.v n < Lib.IntTypes.v clen1} -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires Lib.Buffer.live h0 b1 /\ Lib.Buffer.live h0 b2 /\ Lib.Buffer.live h0 b3 /\ Lib.Buffer.eq_or_disjoint b1 b2 /\ Lib.Buffer.disjoint b1 b3 /\ Lib.Buffer.disjoint b2 b3 /\ Lib.Buffer.modifies (Lib.Buffer.loc (Lib.Buffer.gsub b1 0ul n) |+| Lib.Buffer.loc b3) h0 h1) (ensures (let b2s = Lib.Buffer.gsub b2 n (clen2 -! n) in Lib.Buffer.as_seq h0 b2s == Lib.Buffer.as_seq h1 b2s /\ FStar.Seq.Base.index (Lib.Buffer.as_seq h0 b2) (Lib.IntTypes.v n) == FStar.Seq.Base.index (Lib.Buffer.as_seq h1 b2) (Lib.IntTypes.v n)))
{ "end_col": 93, "end_line": 185, "start_col": 70, "start_line": 179 }
Prims.Tot
val fill_elems : fill_elems_st
[ { "abbrev": true, "full_module": "Hacl.Spec.Lib", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "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 fill_elems #t #a h0 n output refl footprint spec impl = [@inline_let] let refl' h (i:nat{i <= v n}) : GTot (S.generate_elem_a t a (v n) i) = refl h i, as_seq h (gsub output 0ul (size i)) in [@inline_let] let footprint' i = footprint i |+| loc (gsub output 0ul (size i)) in [@inline_let] let spec' h0 = S.generate_elem_f (v n) (spec h0) in let h0 = ST.get () in loop h0 n (S.generate_elem_a t a (v n)) refl' footprint' spec' (fun i -> Loops.unfold_repeat_gen (v n) (S.generate_elem_a t a (v n)) (spec' h0) (refl' h0 0) (v i); impl i; let h = ST.get() in FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i) ); let h1 = ST.get () in assert (refl' h1 (v n) == Loops.repeat_gen (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl' h0 0))
val fill_elems : fill_elems_st let fill_elems #t #a h0 n output refl footprint spec impl =
false
null
false
[@@ inline_let ]let refl' h (i: nat{i <= v n}) : GTot (S.generate_elem_a t a (v n) i) = refl h i, as_seq h (gsub output 0ul (size i)) in [@@ inline_let ]let footprint' i = footprint i |+| loc (gsub output 0ul (size i)) in [@@ inline_let ]let spec' h0 = S.generate_elem_f (v n) (spec h0) in let h0 = ST.get () in loop h0 n (S.generate_elem_a t a (v n)) refl' footprint' spec' (fun i -> Loops.unfold_repeat_gen (v n) (S.generate_elem_a t a (v n)) (spec' h0) (refl' h0 0) (v i); impl i; let h = ST.get () in FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i)); let h1 = ST.get () in assert (refl' h1 (v n) == Loops.repeat_gen (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl' h0 0))
{ "checked_file": "Hacl.Impl.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Lib.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.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.Lib.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_disjoint", "Lib.Buffer.loc", "Lib.Buffer.MUT", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.op_LessThan", "FStar.Pervasives.Native.tuple2", "Prims.unit", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.gsub", "FStar.UInt32.__uint_to_t", "Prims.eq2", "Prims.op_Addition", "Lib.Sequence.index", "Lib.Buffer.as_seq", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Prims._assert", "Hacl.Spec.Lib.generate_elem_a", "Lib.LoopCombinators.repeat_gen", "Hacl.Spec.Lib.generate_elem_f", "FStar.HyperStack.ST.get", "Lib.Buffer.loop", "FStar.Seq.Properties.lemma_split", "Lib.IntTypes.op_Plus_Bang", "Lib.LoopCombinators.unfold_repeat_gen", "Prims.nat", "Prims.op_Subtraction", "Prims.pow2", "Lib.IntTypes.size", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.seq", "Lib.Sequence.length" ]
[]
module Hacl.Impl.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module Loops = Lib.LoopCombinators module S = Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let fill_elems_st = #t:Type0 -> #a:Type0 -> h0:mem -> n:size_t -> output:lbuffer t n -> refl:(mem -> i:size_nat{i <= v n} -> GTot a) -> footprint:(i:size_nat{i <= v n} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < v n} -> a -> a & t)) -> impl:(i:size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o)) inline_for_extraction noextract val fill_elems : fill_elems_st
false
true
Hacl.Impl.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 fill_elems : fill_elems_st
[]
Hacl.Impl.Lib.fill_elems
{ "file_name": "code/bignum/Hacl.Impl.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Lib.fill_elems_st
{ "end_col": 106, "end_line": 68, "start_col": 2, "start_line": 50 }
Prims.Tot
val fill_elems4: fill_elems_st
[ { "abbrev": true, "full_module": "Hacl.Spec.Lib", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "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 fill_elems4 #t #a h0 n output refl footprint spec impl = [@inline_let] let k = n /. 4ul in let tmp = sub output 0ul (4ul *! k) in fill_blocks4 #t #a h0 k tmp refl footprint spec (fun i -> impl i); let h1 = ST.get () in assert (4 * v k + v (n -! 4ul *! k) = v n); B.modifies_buffer_elim (B.gsub #t output (4ul *! k) (n -! 4ul *! k)) (footprint (4 * v k) |+| loc tmp) h0 h1; assert (modifies (footprint (4 * v k) |+| loc (gsub output 0ul (4ul *! k))) h0 h1); let inv (h:mem) (i:nat{4 * v k <= i /\ i <= v n}) = modifies (footprint i |+| loc (gsub output 0ul (size i))) h0 h /\ (let (c, res) = Loops.repeat_right (v n / 4 * 4) i (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) in refl h i == c /\ as_seq h (gsub output 0ul (size i)) == res) in Loops.eq_repeat_right (v n / 4 * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))); Lib.Loops.for (k *! 4ul) n inv (fun i -> impl i; let h = ST.get () in assert (v (i +! 1ul) = v i + 1); FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i); Loops.unfold_repeat_right (v n / 4 * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) (v i) ); S.lemma_generate_elems4 (v n) (v n) (spec h0) (refl h0 0)
val fill_elems4: fill_elems_st let fill_elems4 #t #a h0 n output refl footprint spec impl =
false
null
false
[@@ inline_let ]let k = n /. 4ul in let tmp = sub output 0ul (4ul *! k) in fill_blocks4 #t #a h0 k tmp refl footprint spec (fun i -> impl i); let h1 = ST.get () in assert (4 * v k + v (n -! 4ul *! k) = v n); B.modifies_buffer_elim (B.gsub #t output (4ul *! k) (n -! 4ul *! k)) (footprint (4 * v k) |+| loc tmp) h0 h1; assert (modifies (footprint (4 * v k) |+| loc (gsub output 0ul (4ul *! k))) h0 h1); let inv (h: mem) (i: nat{4 * v k <= i /\ i <= v n}) = modifies (footprint i |+| loc (gsub output 0ul (size i))) h0 h /\ (let c, res = Loops.repeat_right ((v n / 4) * 4) i (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) in refl h i == c /\ as_seq h (gsub output 0ul (size i)) == res) in Loops.eq_repeat_right ((v n / 4) * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))); Lib.Loops.for (k *! 4ul) n inv (fun i -> impl i; let h = ST.get () in assert (v (i +! 1ul) = v i + 1); FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i); Loops.unfold_repeat_right ((v n / 4) * 4) (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl h1 (4 * v k), as_seq h1 (gsub output 0ul (4ul *! k))) (v i)); S.lemma_generate_elems4 (v n) (v n) (spec h0) (refl h0 0)
{ "checked_file": "Hacl.Impl.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Lib.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.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.Lib.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_disjoint", "Lib.Buffer.loc", "Lib.Buffer.MUT", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.op_LessThan", "FStar.Pervasives.Native.tuple2", "Prims.unit", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.gsub", "FStar.UInt32.__uint_to_t", "Prims.eq2", "Prims.op_Addition", "Lib.Sequence.index", "Lib.Buffer.as_seq", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Hacl.Spec.Lib.lemma_generate_elems4", "Lib.Loops.for", "Lib.IntTypes.op_Star_Bang", "Lib.LoopCombinators.unfold_repeat_right", "FStar.Mul.op_Star", "Prims.op_Division", "Hacl.Spec.Lib.generate_elem_a", "Hacl.Spec.Lib.generate_elem_f", "FStar.Pervasives.Native.Mktuple2", "Lib.Sequence.seq", "Prims.nat", "Lib.Sequence.length", "FStar.Seq.Properties.lemma_split", "Lib.IntTypes.op_Plus_Bang", "Prims._assert", "Prims.op_Equality", "Prims.int", "FStar.HyperStack.ST.get", "Lib.LoopCombinators.eq_repeat_right", "Prims.op_Multiply", "Prims.logical", "Lib.IntTypes.size", "Prims.l_or", "FStar.Seq.Base.length", "Lib.LoopCombinators.repeat_right", "LowStar.Monotonic.Buffer.modifies_buffer_elim", "LowStar.Buffer.trivial_preorder", "LowStar.Buffer.gsub", "Lib.IntTypes.op_Subtraction_Bang", "Hacl.Impl.Lib.fill_blocks4", "Lib.IntTypes.mul", "Lib.Buffer.sub", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Slash_Dot" ]
[]
module Hacl.Impl.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module Loops = Lib.LoopCombinators module S = Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let fill_elems_st = #t:Type0 -> #a:Type0 -> h0:mem -> n:size_t -> output:lbuffer t n -> refl:(mem -> i:size_nat{i <= v n} -> GTot a) -> footprint:(i:size_nat{i <= v n} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < v n} -> a -> a & t)) -> impl:(i:size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o)) inline_for_extraction noextract val fill_elems : fill_elems_st let fill_elems #t #a h0 n output refl footprint spec impl = [@inline_let] let refl' h (i:nat{i <= v n}) : GTot (S.generate_elem_a t a (v n) i) = refl h i, as_seq h (gsub output 0ul (size i)) in [@inline_let] let footprint' i = footprint i |+| loc (gsub output 0ul (size i)) in [@inline_let] let spec' h0 = S.generate_elem_f (v n) (spec h0) in let h0 = ST.get () in loop h0 n (S.generate_elem_a t a (v n)) refl' footprint' spec' (fun i -> Loops.unfold_repeat_gen (v n) (S.generate_elem_a t a (v n)) (spec' h0) (refl' h0 0) (v i); impl i; let h = ST.get() in FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i) ); let h1 = ST.get () in assert (refl' h1 (v n) == Loops.repeat_gen (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl' h0 0)) inline_for_extraction noextract val fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o)) let fill_blocks4 #t #a h0 n4 output refl footprint spec impl = fill_blocks h0 4ul n4 output (Loops.fixed_a a) (fun h i -> refl h (4 * i)) (fun i -> footprint (4 * i)) (fun h0 -> S.generate_blocks4_f #t #a (v n4) (spec h0)) (fun i -> let h1 = ST.get () in impl (4ul *! i); impl (4ul *! i +! 1ul); impl (4ul *! i +! 2ul); impl (4ul *! i +! 3ul); let h2 = ST.get () in assert ( let c0, e0 = spec h0 (4 * v i) (refl h1 (4 * v i)) in let c1, e1 = spec h0 (4 * v i + 1) c0 in let c2, e2 = spec h0 (4 * v i + 2) c1 in let c3, e3 = spec h0 (4 * v i + 3) c2 in let res = LSeq.create4 e0 e1 e2 e3 in LSeq.create4_lemma e0 e1 e2 e3; let res1 = LSeq.sub (as_seq h2 output) (4 * v i) 4 in refl h2 (4 * v i + 4) == c3 /\ (LSeq.eq_intro res res1; res1 `LSeq.equal` res)) ) inline_for_extraction noextract val fill_elems4: fill_elems_st
false
true
Hacl.Impl.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 fill_elems4: fill_elems_st
[]
Hacl.Impl.Lib.fill_elems4
{ "file_name": "code/bignum/Hacl.Impl.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.Lib.fill_elems_st
{ "end_col": 59, "end_line": 153, "start_col": 2, "start_line": 126 }
FStar.HyperStack.ST.Stack
val fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o))
[ { "abbrev": true, "full_module": "Hacl.Spec.Lib", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "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 fill_blocks4 #t #a h0 n4 output refl footprint spec impl = fill_blocks h0 4ul n4 output (Loops.fixed_a a) (fun h i -> refl h (4 * i)) (fun i -> footprint (4 * i)) (fun h0 -> S.generate_blocks4_f #t #a (v n4) (spec h0)) (fun i -> let h1 = ST.get () in impl (4ul *! i); impl (4ul *! i +! 1ul); impl (4ul *! i +! 2ul); impl (4ul *! i +! 3ul); let h2 = ST.get () in assert ( let c0, e0 = spec h0 (4 * v i) (refl h1 (4 * v i)) in let c1, e1 = spec h0 (4 * v i + 1) c0 in let c2, e2 = spec h0 (4 * v i + 2) c1 in let c3, e3 = spec h0 (4 * v i + 3) c2 in let res = LSeq.create4 e0 e1 e2 e3 in LSeq.create4_lemma e0 e1 e2 e3; let res1 = LSeq.sub (as_seq h2 output) (4 * v i) 4 in refl h2 (4 * v i + 4) == c3 /\ (LSeq.eq_intro res res1; res1 `LSeq.equal` res)) )
val fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o)) let fill_blocks4 #t #a h0 n4 output refl footprint spec impl =
true
null
false
fill_blocks h0 4ul n4 output (Loops.fixed_a a) (fun h i -> refl h (4 * i)) (fun i -> footprint (4 * i)) (fun h0 -> S.generate_blocks4_f #t #a (v n4) (spec h0)) (fun i -> let h1 = ST.get () in impl (4ul *! i); impl (4ul *! i +! 1ul); impl (4ul *! i +! 2ul); impl (4ul *! i +! 3ul); let h2 = ST.get () in assert (let c0, e0 = spec h0 (4 * v i) (refl h1 (4 * v i)) in let c1, e1 = spec h0 (4 * v i + 1) c0 in let c2, e2 = spec h0 (4 * v i + 2) c1 in let c3, e3 = spec h0 (4 * v i + 3) c2 in let res = LSeq.create4 e0 e1 e2 e3 in LSeq.create4_lemma e0 e1 e2 e3; let res1 = LSeq.sub (as_seq h2 output) (4 * v i) 4 in refl h2 (4 * v i + 4) == c3 /\ (LSeq.eq_intro res res1; res1 `LSeq.equal` res)))
{ "checked_file": "Hacl.Impl.Lib.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Lib.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.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.Lib.fst" }
[]
[ "FStar.Monotonic.HyperStack.mem", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.op_Star_Bang", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_nat", "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_disjoint", "Lib.Buffer.loc", "Lib.Buffer.MUT", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.op_LessThan", "FStar.Pervasives.Native.tuple2", "Prims.unit", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.gsub", "Prims.eq2", "Prims.op_Addition", "Lib.Sequence.index", "Lib.Buffer.as_seq", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.fill_blocks", "Lib.LoopCombinators.fixed_a", "Hacl.Spec.Lib.generate_blocks4_f", "Lib.Sequence.lseq", "Prims._assert", "Lib.Sequence.equal", "Lib.Sequence.eq_intro", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Lib.IntTypes.mul", "Prims.op_Multiply", "Prims.l_Forall", "Prims.nat", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.sub", "Lib.Sequence.create4_lemma", "Lib.Sequence.create4", "FStar.HyperStack.ST.get", "Lib.IntTypes.op_Plus_Bang" ]
[]
module Hacl.Impl.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module Loops = Lib.LoopCombinators module S = Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let fill_elems_st = #t:Type0 -> #a:Type0 -> h0:mem -> n:size_t -> output:lbuffer t n -> refl:(mem -> i:size_nat{i <= v n} -> GTot a) -> footprint:(i:size_nat{i <= v n} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < v n} -> a -> a & t)) -> impl:(i:size_t{v i < v n} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (v n) |+| loc output) h0 h1 /\ (let s, o = S.generate_elems (v n) (v n) (spec h0) (refl h0 0) in refl h1 (v n) == s /\ as_seq #_ #t h1 output == o)) inline_for_extraction noextract val fill_elems : fill_elems_st let fill_elems #t #a h0 n output refl footprint spec impl = [@inline_let] let refl' h (i:nat{i <= v n}) : GTot (S.generate_elem_a t a (v n) i) = refl h i, as_seq h (gsub output 0ul (size i)) in [@inline_let] let footprint' i = footprint i |+| loc (gsub output 0ul (size i)) in [@inline_let] let spec' h0 = S.generate_elem_f (v n) (spec h0) in let h0 = ST.get () in loop h0 n (S.generate_elem_a t a (v n)) refl' footprint' spec' (fun i -> Loops.unfold_repeat_gen (v n) (S.generate_elem_a t a (v n)) (spec' h0) (refl' h0 0) (v i); impl i; let h = ST.get() in FStar.Seq.lemma_split (as_seq h (gsub output 0ul (i +! 1ul))) (v i) ); let h1 = ST.get () in assert (refl' h1 (v n) == Loops.repeat_gen (v n) (S.generate_elem_a t a (v n)) (S.generate_elem_f (v n) (spec h0)) (refl' h0 0)) inline_for_extraction noextract val fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o))
false
false
Hacl.Impl.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 fill_blocks4: #t:Type0 -> #a:Type0 -> h0:mem -> n4:size_t{4 * v n4 <= max_size_t} -> output:lbuffer t (4ul *! n4) -> refl:(mem -> i:size_nat{i <= 4 * v n4} -> GTot a) -> footprint:(i:size_nat{i <= 4 * v n4} -> GTot (l:B.loc{B.loc_disjoint l (loc output) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})) -> spec:(mem -> GTot (i:size_nat{i < 4 * v n4} -> a -> a & t)) -> impl:(i:size_t{v i < 4 * v n4} -> Stack unit (requires fun h -> modifies (footprint (v i) |+| loc (gsub output 0ul i)) h0 h) (ensures fun h1 _ h2 -> (let block1 = gsub output i 1ul in let c, e = spec h0 (v i) (refl h1 (v i)) in refl h2 (v i + 1) == c /\ LSeq.index (as_seq h2 block1) 0 == e /\ footprint (v i + 1) `B.loc_includes` footprint (v i) /\ modifies (footprint (v i + 1) |+| (loc block1)) h1 h2))) -> Stack unit (requires fun h -> h0 == h /\ live h output) (ensures fun _ _ h1 -> modifies (footprint (4 * v n4) |+| loc output) h0 h1 /\ (let s, o = LSeq.generate_blocks 4 (v n4) (v n4) (Loops.fixed_a a) (S.generate_blocks4_f #t #a (v n4) (spec h0)) (refl h0 0) in refl h1 (4 * v n4) == s /\ as_seq #_ #t h1 output == o))
[]
Hacl.Impl.Lib.fill_blocks4
{ "file_name": "code/bignum/Hacl.Impl.Lib.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> n4: Lib.IntTypes.size_t{4 * Lib.IntTypes.v n4 <= Lib.IntTypes.max_size_t} -> output: Lib.Buffer.lbuffer t (4ul *! n4) -> refl: (_: FStar.Monotonic.HyperStack.mem -> i: Lib.IntTypes.size_nat{i <= 4 * Lib.IntTypes.v n4} -> Prims.GTot a) -> footprint: (i: Lib.IntTypes.size_nat{i <= 4 * Lib.IntTypes.v n4} -> Prims.GTot (l: LowStar.Monotonic.Buffer.loc { LowStar.Monotonic.Buffer.loc_disjoint l (Lib.Buffer.loc output) /\ LowStar.Monotonic.Buffer.loc_includes LowStar.Monotonic.Buffer.address_liveness_insensitive_locs l })) -> spec: (_: FStar.Monotonic.HyperStack.mem -> Prims.GTot (i: Lib.IntTypes.size_nat{i < 4 * Lib.IntTypes.v n4} -> _: a -> a * t)) -> impl: (i: Lib.IntTypes.size_t{Lib.IntTypes.v i < 4 * Lib.IntTypes.v n4} -> FStar.HyperStack.ST.Stack Prims.unit) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 3, "end_line": 120, "start_col": 2, "start_line": 99 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq
let t128_imm =
false
null
false
TD_ImmBuffer TUInt32 TUInt128 default_bq
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.TD_ImmBuffer", "Vale.Arch.HeapTypes_s.TUInt32", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Base.default_bq" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t128_imm : Vale.Interop.Base.td
[]
Vale.Stdcalls.X64.Sha.t128_imm
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.Interop.Base.td
{ "end_col": 55, "end_line": 47, "start_col": 15, "start_line": 47 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 tuint64 = TD_Base TUInt64
let tuint64 =
false
null
false
TD_Base TUInt64
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.TD_Base", "Vale.Arch.HeapTypes_s.TUInt64" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tuint64 : Vale.Interop.Base.td
[]
Vale.Stdcalls.X64.Sha.tuint64
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.Interop.Base.td
{ "end_col": 29, "end_line": 49, "start_col": 14, "start_line": 49 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 b128 = buf_t TUInt32 TUInt128
let b128 =
false
null
false
buf_t TUInt32 TUInt128
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.buf_t", "Vale.Arch.HeapTypes_s.TUInt32", "Vale.Arch.HeapTypes_s.TUInt128" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val b128 : Type0
[]
Vale.Stdcalls.X64.Sha.b128
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 33, "end_line": 37, "start_col": 11, "start_line": 37 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 b8_128 = buf_t TUInt8 TUInt128
let b8_128 =
false
null
false
buf_t TUInt8 TUInt128
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.buf_t", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val b8_128 : Type0
[]
Vale.Stdcalls.X64.Sha.b8_128
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 34, "end_line": 39, "start_col": 13, "start_line": 39 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 t128_mod = TD_Buffer TUInt32 TUInt128 default_bq
let t128_mod =
false
null
false
TD_Buffer TUInt32 TUInt128 default_bq
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt32", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Base.default_bq" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t128_mod : Vale.Interop.Base.td
[]
Vale.Stdcalls.X64.Sha.t128_mod
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.Interop.Base.td
{ "end_col": 52, "end_line": 43, "start_col": 15, "start_line": 43 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 ib128 = ibuf_t TUInt32 TUInt128
let ib128 =
false
null
false
ibuf_t TUInt32 TUInt128
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.ibuf_t", "Vale.Arch.HeapTypes_s.TUInt32", "Vale.Arch.HeapTypes_s.TUInt128" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ib128 : Type0
[]
Vale.Stdcalls.X64.Sha.ib128
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 35, "end_line": 41, "start_col": 12, "start_line": 41 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 uint64 = UInt64.t
let uint64 =
false
null
false
UInt64.t
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "FStar.UInt64.t" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uint64 : Prims.eqtype
[]
Vale.Stdcalls.X64.Sha.uint64
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.eqtype
{ "end_col": 21, "end_line": 28, "start_col": 13, "start_line": 28 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 code_sha = SH.va_code_Sha_update_bytes_stdcall IA.win
let code_sha =
false
null
false
SH.va_code_Sha_update_bytes_stdcall IA.win
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.SHA.X64.va_code_Sha_update_bytes_stdcall", "Vale.Interop.Assumptions.win" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_pre : VSig.vale_pre dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_post : VSig.vale_post dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> SH.va_ens_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) va_s1 f module VS = Vale.X64.State #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@__reduce__] noextract let sha_lemma' (code:V.va_code) (_win:bool) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b) )) = let va_s1, f = SH.va_lemma_Sha_update_bytes_stdcall code va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt32 ME.TUInt128 ctx_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; (va_s1, f) (* Prove that sha_lemma' has the required type *) noextract let sha_lemma = as_t #(VSig.vale_sig_stdcall sha_pre sha_post) sha_lemma'
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val code_sha : Vale.X64.Decls.va_code
[]
Vale.Stdcalls.X64.Sha.code_sha
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.X64.Decls.va_code
{ "end_col": 57, "end_line": 117, "start_col": 15, "start_line": 117 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
let t128_no_mod =
false
null
false
TD_Buffer TUInt8 TUInt128 ({ modified = false; strict_disjointness = false; taint = MS.Secret })
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Base.Mkbuffer_qualifiers", "Vale.Arch.HeapTypes_s.Secret" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t128_no_mod : Vale.Interop.Base.td
[]
Vale.Stdcalls.X64.Sha.t128_no_mod
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.Interop.Base.td
{ "end_col": 106, "end_line": 45, "start_col": 18, "start_line": 45 }
Prims.Tot
val as_normal_t (#a: Type) (x: a) : normal a
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 as_normal_t (#a:Type) (x:a) : normal a = x
val as_normal_t (#a: Type) (x: a) : normal a let as_normal_t (#a: Type) (x: a) : normal a =
false
null
false
x
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.normal" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x
false
false
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val as_normal_t (#a: Type) (x: a) : normal a
[]
Vale.Stdcalls.X64.Sha.as_normal_t
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: a -> Vale.Interop.Base.normal a
{ "end_col": 46, "end_line": 34, "start_col": 45, "start_line": 34 }
Prims.Tot
val as_t (#a: Type) (x: normal a) : a
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 as_t (#a:Type) (x:normal a) : a = x
val as_t (#a: Type) (x: normal a) : a let as_t (#a: Type) (x: normal a) : a =
false
null
false
x
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.Base.normal" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *)
false
false
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val as_t (#a: Type) (x: normal a) : a
[]
Vale.Stdcalls.X64.Sha.as_t
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Vale.Interop.Base.normal a -> a
{ "end_col": 39, "end_line": 32, "start_col": 38, "start_line": 32 }
Prims.Tot
val dom:IX64.arity_ok_stdcall td
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y
val dom:IX64.arity_ok_stdcall td let dom:IX64.arity_ok_stdcall td =
false
null
false
let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Vale.Interop.Base.td", "Prims.list", "Prims.Cons", "Vale.Stdcalls.X64.Sha.t128_mod", "Vale.Stdcalls.X64.Sha.t128_no_mod", "Vale.Stdcalls.X64.Sha.tuint64", "Vale.Stdcalls.X64.Sha.t128_imm", "Prims.Nil" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__]
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dom:IX64.arity_ok_stdcall td
[]
Vale.Stdcalls.X64.Sha.dom
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.Interop.X64.arity_ok_stdcall Vale.Interop.Base.td
{ "end_col": 3, "end_line": 56, "start_col": 35, "start_line": 53 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 lowstar_sha_t = IX64.as_lowstar_sig_t_weak_stdcall code_sha dom [] _ _ (W.mk_prediction code_sha dom [] (sha_lemma code_sha IA.win))
let lowstar_sha_t =
false
null
false
IX64.as_lowstar_sig_t_weak_stdcall code_sha dom [] _ _ (W.mk_prediction code_sha dom [] (sha_lemma code_sha IA.win))
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.Stdcalls.X64.Sha.code_sha", "Vale.Stdcalls.X64.Sha.dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.Stdcalls.X64.Sha.sha_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.Stdcalls.X64.Sha.sha_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.Stdcalls.X64.Sha.sha_lemma", "Vale.Interop.Assumptions.win" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_pre : VSig.vale_pre dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_post : VSig.vale_post dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> SH.va_ens_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) va_s1 f module VS = Vale.X64.State #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@__reduce__] noextract let sha_lemma' (code:V.va_code) (_win:bool) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b) )) = let va_s1, f = SH.va_lemma_Sha_update_bytes_stdcall code va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt32 ME.TUInt128 ctx_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; (va_s1, f) (* Prove that sha_lemma' has the required type *) noextract let sha_lemma = as_t #(VSig.vale_sig_stdcall sha_pre sha_post) sha_lemma' noextract let code_sha = SH.va_code_Sha_update_bytes_stdcall IA.win #reset-options "--z3rlimit 20" (* Here's the type expected for the sha wrapper *) [@__reduce__] noextract
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lowstar_sha_t : Type0
[]
Vale.Stdcalls.X64.Sha.lowstar_sha_t
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 65, "end_line": 130, "start_col": 2, "start_line": 124 }
Prims.Tot
val sha_pre:VSig.vale_pre dom
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 sha_pre : VSig.vale_pre dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b)
val sha_pre:VSig.vale_pre dom let sha_pre:VSig.vale_pre dom =
false
null
false
fun (c: V.va_code) (ctx_b: b128) (in_b: b8_128) (num_val: uint64) (k_b: ib128) (va_s0: V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b)
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.Sha.b128", "Vale.Stdcalls.X64.Sha.b8_128", "Vale.Stdcalls.X64.Sha.uint64", "Vale.Stdcalls.X64.Sha.ib128", "Vale.X64.Decls.va_state", "Vale.SHA.X64.va_req_Sha_update_bytes_stdcall", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt32", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Arch.HeapTypes_s.TUInt8", "FStar.UInt64.v", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Prims.prop" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha_pre:VSig.vale_pre dom
[]
Vale.Stdcalls.X64.Sha.sha_pre
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.Sha.dom
{ "end_col": 95, "end_line": 68, "start_col": 2, "start_line": 61 }
Prims.Tot
val sha_post:VSig.vale_post dom
[ { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 sha_post : VSig.vale_post dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> SH.va_ens_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) va_s1 f
val sha_post:VSig.vale_post dom let sha_post:VSig.vale_post dom =
false
null
false
fun (c: V.va_code) (ctx_b: b128) (in_b: b8_128) (num_val: uint64) (k_b: ib128) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> SH.va_ens_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) va_s1 f
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.Sha.b128", "Vale.Stdcalls.X64.Sha.b8_128", "Vale.Stdcalls.X64.Sha.uint64", "Vale.Stdcalls.X64.Sha.ib128", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.SHA.X64.va_ens_Sha_update_bytes_stdcall", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt32", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Arch.HeapTypes_s.TUInt8", "FStar.UInt64.v", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Prims.prop" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_pre : VSig.vale_pre dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) (* Need to rearrange the order of arguments *) [@__reduce__] noextract
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha_post:VSig.vale_post dom
[]
Vale.Stdcalls.X64.Sha.sha_post
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.Sha.dom
{ "end_col": 15, "end_line": 83, "start_col": 2, "start_line": 73 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 sha_lemma = as_t #(VSig.vale_sig_stdcall sha_pre sha_post) sha_lemma'
let sha_lemma =
false
null
false
as_t #(VSig.vale_sig_stdcall sha_pre sha_post) sha_lemma'
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[ "total" ]
[ "Vale.Stdcalls.X64.Sha.as_t", "Vale.AsLowStar.ValeSig.vale_sig_stdcall", "Vale.Stdcalls.X64.Sha.dom", "Vale.Stdcalls.X64.Sha.sha_pre", "Vale.Stdcalls.X64.Sha.sha_post", "Vale.Stdcalls.X64.Sha.sha_lemma'" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_pre : VSig.vale_pre dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_post : VSig.vale_post dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> SH.va_ens_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) va_s1 f module VS = Vale.X64.State #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@__reduce__] noextract let sha_lemma' (code:V.va_code) (_win:bool) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b) )) = let va_s1, f = SH.va_lemma_Sha_update_bytes_stdcall code va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt32 ME.TUInt128 ctx_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; (va_s1, f) (* Prove that sha_lemma' has the required type *)
false
true
Vale.Stdcalls.X64.Sha.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha_lemma : Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.Stdcalls.X64.Sha.sha_pre Vale.Stdcalls.X64.Sha.sha_post
[]
Vale.Stdcalls.X64.Sha.sha_lemma
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.Stdcalls.X64.Sha.sha_pre Vale.Stdcalls.X64.Sha.sha_post
{ "end_col": 73, "end_line": 115, "start_col": 16, "start_line": 115 }
Prims.Ghost
val sha_lemma' (code: V.va_code) (_win: bool) (ctx_b: b128) (in_b: b8_128) (num_val: uint64) (k_b: ib128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b)) )
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.SHA.X64", "short_module": "SH" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "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 sha_lemma' (code:V.va_code) (_win:bool) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b) )) = let va_s1, f = SH.va_lemma_Sha_update_bytes_stdcall code va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt32 ME.TUInt128 ctx_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; (va_s1, f)
val sha_lemma' (code: V.va_code) (_win: bool) (ctx_b: b128) (in_b: b8_128) (num_val: uint64) (k_b: ib128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b)) ) let sha_lemma' (code: V.va_code) (_win: bool) (ctx_b: b128) (in_b: b8_128) (num_val: uint64) (k_b: ib128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b)) ) =
false
null
false
let va_s1, f = SH.va_lemma_Sha_update_bytes_stdcall code va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt32 ME.TUInt128 ctx_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in_b; (va_s1, f)
{ "checked_file": "Vale.Stdcalls.X64.Sha.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.SHA.X64.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.Sha.fsti" }
[]
[ "Vale.X64.Decls.va_code", "Prims.bool", "Vale.Stdcalls.X64.Sha.b128", "Vale.Stdcalls.X64.Sha.b8_128", "Vale.Stdcalls.X64.Sha.uint64", "Vale.Stdcalls.X64.Sha.ib128", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Arch.HeapTypes_s.TUInt32", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.SHA.X64.va_lemma_Sha_update_bytes_stdcall", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_buffer", "FStar.UInt64.v", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Vale.Stdcalls.X64.Sha.sha_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.Stdcalls.X64.Sha.sha_post", "Vale.X64.Memory.buffer_writeable" ]
[]
module Vale.Stdcalls.X64.Sha open FStar.Mul val z3rlimit_hack (x:nat) : squash (x < x + x + 1) #reset-options "--z3rlimit 50" open FStar.HyperStack.ST module HS = FStar.HyperStack module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module DV = LowStar.BufferView.Down open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s module SH = Vale.SHA.X64 let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt32 TUInt128 [@__reduce__] noextract let b8_128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let ib128 = ibuf_t TUInt32 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let t128_imm = TD_ImmBuffer TUInt32 TUInt128 default_bq [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_mod; t128_no_mod; tuint64; t128_imm] in assert_norm (List.length y = 4); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_pre : VSig.vale_pre dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) -> SH.va_req_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let sha_post : VSig.vale_post dom = fun (c:V.va_code) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> SH.va_ens_Sha_update_bytes_stdcall c va_s0 IA.win (as_vale_buffer ctx_b) (as_vale_buffer in_b) (UInt64.v num_val) (as_vale_immbuffer k_b) va_s1 f module VS = Vale.X64.State #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@__reduce__] noextract let sha_lemma' (code:V.va_code) (_win:bool) (ctx_b:b128) (in_b:b8_128) (num_val:uint64) (k_b:ib128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\
false
false
Vale.Stdcalls.X64.Sha.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "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": 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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha_lemma' (code: V.va_code) (_win: bool) (ctx_b: b128) (in_b: b8_128) (num_val: uint64) (k_b: ib128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires sha_pre code ctx_b in_b num_val k_b va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ sha_post code ctx_b in_b num_val k_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer ctx_b) /\ ME.buffer_writeable (as_vale_buffer in_b)) )
[]
Vale.Stdcalls.X64.Sha.sha_lemma'
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Sha.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
code: Vale.X64.Decls.va_code -> _win: Prims.bool -> ctx_b: Vale.Stdcalls.X64.Sha.b128 -> in_b: Vale.Stdcalls.X64.Sha.b8_128 -> num_val: Vale.Stdcalls.X64.Sha.uint64 -> k_b: Vale.Stdcalls.X64.Sha.ib128 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
{ "end_col": 13, "end_line": 111, "start_col": 5, "start_line": 107 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 a = B.pointer (state_s a)
let state a =
false
null
false
B.pointer (state_s a)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "LowStar.Buffer.pointer", "EverCrypt.DRBG.state_s" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0
false
true
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state : a: EverCrypt.DRBG.supported_alg -> Type0
[]
EverCrypt.DRBG.state
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: EverCrypt.DRBG.supported_alg -> Type0
{ "end_col": 35, "end_line": 97, "start_col": 14, "start_line": 97 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 preserves_freeable #a (st:state a) (h0 h1:HS.mem) = freeable st h0 ==> freeable st h1
let preserves_freeable #a (st: state a) (h0: HS.mem) (h1: HS.mem) =
false
null
false
freeable st h0 ==> freeable st h1
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "EverCrypt.DRBG.freeable", "Prims.logical" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h inline_for_extraction noextract let disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem) = B.loc_disjoint (footprint st h) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) /// TR: the following pattern is necessary because, if we generically /// add such a pattern directly on `loc_includes_union_l`, then /// verification will blowup whenever both sides of `loc_includes` are /// `loc_union`s. We would like to break all unions on the /// right-hand-side of `loc_includes` first, using /// `loc_includes_union_r`. Here the pattern is on `footprint_s`, /// because we already expose the fact that `footprint` is a /// `loc_union`. (In other words, the pattern should be on every /// smallest location that is not exposed to be a `loc_union`.) /// val loc_includes_union_l_footprint_s: #a:supported_alg -> l1:B.loc -> l2:B.loc -> st:state_s a -> Lemma (requires B.loc_includes l1 (footprint_s st) \/ B.loc_includes l2 (footprint_s st)) (ensures B.loc_includes (B.loc_union l1 l2) (footprint_s st)) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s st))] /// Needed to prove that the footprint is disjoint from any fresh location val invariant_loc_in_footprint: #a:supported_alg -> st:state a -> h:HS.mem -> Lemma (requires invariant st h) (ensures B.loc_in (footprint st h) h) [SMTPat (invariant st h)] val frame_invariant: #a:supported_alg -> l:B.loc -> st:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires invariant st h0 /\ B.loc_disjoint l (footprint st h0) /\ B.modifies l h0 h1) (ensures invariant st h1 /\ repr st h0 == repr st h1) inline_for_extraction noextract
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val preserves_freeable : st: EverCrypt.DRBG.state a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Prims.logical
[]
EverCrypt.DRBG.preserves_freeable
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
st: EverCrypt.DRBG.state a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Prims.logical
{ "end_col": 35, "end_line": 163, "start_col": 2, "start_line": 163 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st)
let freeable (#a: supported_alg) (st: state a) (h: HS.mem) =
false
null
false
B.freeable st /\ freeable_s (B.deref h st)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.freeable", "EverCrypt.DRBG.state_s", "LowStar.Buffer.trivial_preorder", "EverCrypt.DRBG.freeable_s", "LowStar.Monotonic.Buffer.deref", "Prims.logical" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val freeable : st: EverCrypt.DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Prims.logical
[]
EverCrypt.DRBG.freeable
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
st: EverCrypt.DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Prims.logical
{ "end_col": 44, "end_line": 104, "start_col": 2, "start_line": 104 }
Prims.GTot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st))
let footprint (#a: supported_alg) (st: state a) (h: HS.mem) =
false
null
false
B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st))
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "sometrivial" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.DRBG.state_s", "LowStar.Buffer.trivial_preorder", "EverCrypt.DRBG.footprint_s", "LowStar.Monotonic.Buffer.deref", "LowStar.Monotonic.Buffer.loc" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val footprint : st: EverCrypt.DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot LowStar.Monotonic.Buffer.loc
[]
EverCrypt.DRBG.footprint
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
st: EverCrypt.DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot LowStar.Monotonic.Buffer.loc
{ "end_col": 68, "end_line": 109, "start_col": 2, "start_line": 109 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem) = B.loc_disjoint (footprint st h) (B.loc_buffer b)
let disjoint_st (#t: Type) (#a: supported_alg) (st: state a) (b: B.buffer t) (h: HS.mem) =
false
null
false
B.loc_disjoint (footprint st h) (B.loc_buffer b)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "LowStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc_disjoint", "EverCrypt.DRBG.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h inline_for_extraction noextract let disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem)
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_st : st: EverCrypt.DRBG.state a -> b: LowStar.Buffer.buffer t -> h: FStar.Monotonic.HyperStack.mem -> Type0
[]
EverCrypt.DRBG.disjoint_st
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
st: EverCrypt.DRBG.state a -> b: LowStar.Buffer.buffer t -> h: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 50, "end_line": 124, "start_col": 2, "start_line": 124 }
Prims.Tot
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 supported_alg = S.supported_alg
let supported_alg =
false
null
false
S.supported_alg
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "Spec.HMAC_DRBG.supported_alg" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it
false
true
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val supported_alg : Type0
[]
EverCrypt.DRBG.supported_alg
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 35, "end_line": 54, "start_col": 20, "start_line": 54 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h
let invariant (#a: supported_alg) (st: state a) (h: HS.mem) =
false
null
false
B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "EverCrypt.DRBG.state_s", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.DRBG.footprint_s", "LowStar.Monotonic.Buffer.deref", "EverCrypt.DRBG.invariant_s", "Prims.logical" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val invariant : st: EverCrypt.DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Prims.logical
[]
EverCrypt.DRBG.invariant
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
st: EverCrypt.DRBG.state a -> h: FStar.Monotonic.HyperStack.mem -> Prims.logical
{ "end_col": 30, "end_line": 118, "start_col": 2, "start_line": 116 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 uninstantiate_st (a:supported_alg) = st:state a -> ST unit (requires fun h0 -> freeable st h0 /\ invariant st h0) (ensures fun h0 _ h1 -> B.modifies (footprint st h0) h0 h1)
let uninstantiate_st (a: supported_alg) =
false
null
false
st: state a -> ST unit (requires fun h0 -> freeable st h0 /\ invariant st h0) (ensures fun h0 _ h1 -> B.modifies (footprint st h0) h0 h1)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverCrypt.DRBG.freeable", "EverCrypt.DRBG.invariant", "LowStar.Monotonic.Buffer.modifies", "EverCrypt.DRBG.footprint" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h inline_for_extraction noextract let disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem) = B.loc_disjoint (footprint st h) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) /// TR: the following pattern is necessary because, if we generically /// add such a pattern directly on `loc_includes_union_l`, then /// verification will blowup whenever both sides of `loc_includes` are /// `loc_union`s. We would like to break all unions on the /// right-hand-side of `loc_includes` first, using /// `loc_includes_union_r`. Here the pattern is on `footprint_s`, /// because we already expose the fact that `footprint` is a /// `loc_union`. (In other words, the pattern should be on every /// smallest location that is not exposed to be a `loc_union`.) /// val loc_includes_union_l_footprint_s: #a:supported_alg -> l1:B.loc -> l2:B.loc -> st:state_s a -> Lemma (requires B.loc_includes l1 (footprint_s st) \/ B.loc_includes l2 (footprint_s st)) (ensures B.loc_includes (B.loc_union l1 l2) (footprint_s st)) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s st))] /// Needed to prove that the footprint is disjoint from any fresh location val invariant_loc_in_footprint: #a:supported_alg -> st:state a -> h:HS.mem -> Lemma (requires invariant st h) (ensures B.loc_in (footprint st h) h) [SMTPat (invariant st h)] val frame_invariant: #a:supported_alg -> l:B.loc -> st:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires invariant st h0 /\ B.loc_disjoint l (footprint st h0) /\ B.modifies l h0 h1) (ensures invariant st h1 /\ repr st h0 == repr st h1) inline_for_extraction noextract let preserves_freeable #a (st:state a) (h0 h1:HS.mem) = freeable st h0 ==> freeable st h1 inline_for_extraction val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1) val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1) (** @type: true *) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`. @return DRBG state. Needs to be freed via `EverCrypt_DRBG_uninstantiate`."] val create: a:supported_alg -> ST (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ invariant st h1 /\ freeable st h1) inline_for_extraction noextract let instantiate_st (a:supported_alg) = st:state a -> personalization_string:B.buffer uint8 -> personalization_string_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 personalization_string /\ disjoint_st st personalization_string h0 /\ B.length personalization_string = v personalization_string_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v personalization_string_len <= S.max_personalization_string_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input nonce. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ S.min_length a / 2 <= Seq.length nonce /\ Seq.length nonce <= S.max_length /\ repr st h1 == S.instantiate entropy_input nonce (B.as_seq h0 personalization_string))) inline_for_extraction noextract let reseed_st (a:supported_alg) = st:state a -> additional_input:B.buffer uint8 -> additional_input_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 additional_input /\ disjoint_st st additional_input h0 /\ B.length additional_input = v additional_input_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v additional_input_len <= S.max_additional_input_length /\ footprint st h0 == footprint st h1 /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ repr st h1 == S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input))) inline_for_extraction noextract let generate_st (a:supported_alg) = output:B.buffer uint8 -> st:state a -> n:size_t -> additional_input:B.buffer uint8 -> additional_input_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 output /\ B.live h0 additional_input /\ disjoint_st st output h0 /\ disjoint_st st additional_input h0 /\ B.disjoint output additional_input /\ B.length additional_input = v additional_input_len /\ v n = B.length output) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v n <= S.max_output_length /\ v additional_input_len <= S.max_additional_input_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (B.loc_union (B.loc_buffer output) (footprint st h0)) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ (let st1 = S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input) in match S.generate st1 (v n) (B.as_seq h0 additional_input) with | None -> False // Always reseeds, so generation cannot fail | Some (out, st_) -> repr st h1 == st_ /\ B.as_seq h1 output == out))) inline_for_extraction noextract
false
true
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uninstantiate_st : a: EverCrypt.DRBG.supported_alg -> Type0
[]
EverCrypt.DRBG.uninstantiate_st
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: EverCrypt.DRBG.supported_alg -> Type0
{ "end_col": 62, "end_line": 303, "start_col": 4, "start_line": 300 }
Prims.Tot
val max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length}
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length)
val max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length} let max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length} =
false
null
false
assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_personalization_string_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ]
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_personalization_string_length:n: size_t{v n == S.max_personalization_string_length}
[]
EverCrypt.DRBG.max_personalization_string_length
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_personalization_string_length}
{ "end_col": 61, "end_line": 74, "start_col": 2, "start_line": 73 }
Prims.Tot
val max_length:n: size_t{v n == S.max_length}
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length)
val max_length:n: size_t{v n == S.max_length} let max_length:n: size_t{v n == S.max_length} =
false
null
false
assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ]
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_length:n: size_t{v n == S.max_length}
[]
EverCrypt.DRBG.max_length
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_length}
{ "end_col": 38, "end_line": 69, "start_col": 2, "start_line": 68 }
Prims.Tot
val max_additional_input_length:n: size_t{v n == S.max_additional_input_length}
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length)
val max_additional_input_length:n: size_t{v n == S.max_additional_input_length} let max_additional_input_length:n: size_t{v n == S.max_additional_input_length} =
false
null
false
assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_additional_input_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ]
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_additional_input_length:n: size_t{v n == S.max_additional_input_length}
[]
EverCrypt.DRBG.max_additional_input_length
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_additional_input_length}
{ "end_col": 55, "end_line": 79, "start_col": 2, "start_line": 78 }
Prims.Tot
val max_output_length:n: size_t{v n == S.max_output_length}
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length)
val max_output_length:n: size_t{v n == S.max_output_length} let max_output_length:n: size_t{v n == S.max_output_length} =
false
null
false
assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.max_output_length", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ]
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_output_length:n: size_t{v n == S.max_output_length}
[]
EverCrypt.DRBG.max_output_length
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.max_output_length}
{ "end_col": 45, "end_line": 64, "start_col": 2, "start_line": 63 }
Prims.Tot
val min_length (a: supported_alg) : n: size_t{v n == S.min_length a}
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256))
val min_length (a: supported_alg) : n: size_t{v n == S.min_length a} let min_length (a: supported_alg) : n: size_t{v n == S.min_length a} =
false
null
false
assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256))
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_t", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.HMAC_DRBG.min_length", "Lib.IntTypes.mk_int", "Spec.Hash.Definitions.SHA1", "Spec.Hash.Definitions.SHA2_256", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length)
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val min_length (a: supported_alg) : n: size_t{v n == S.min_length a}
[]
EverCrypt.DRBG.min_length
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: EverCrypt.DRBG.supported_alg -> n: Lib.IntTypes.size_t{Lib.IntTypes.v n == Spec.HMAC_DRBG.min_length a}
{ "end_col": 85, "end_line": 85, "start_col": 2, "start_line": 82 }
Prims.Tot
val reseed_interval:n: size_t{v n == S.reseed_interval}
[ { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval)
val reseed_interval:n: size_t{v n == S.reseed_interval} let reseed_interval:n: size_t{v n == S.reseed_interval} =
false
null
false
assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval)
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "FStar.Pervasives.normalize_term", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Spec.HMAC_DRBG.reseed_interval", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.pow2" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ]
false
false
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reseed_interval:n: size_t{v n == S.reseed_interval}
[]
EverCrypt.DRBG.reseed_interval
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v n == Spec.HMAC_DRBG.reseed_interval}
{ "end_col": 43, "end_line": 59, "start_col": 2, "start_line": 58 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 reseed_st (a:supported_alg) = st:state a -> additional_input:B.buffer uint8 -> additional_input_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 additional_input /\ disjoint_st st additional_input h0 /\ B.length additional_input = v additional_input_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v additional_input_len <= S.max_additional_input_length /\ footprint st h0 == footprint st h1 /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ repr st h1 == S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input)))
let reseed_st (a: supported_alg) =
false
null
false
st: state a -> additional_input: B.buffer uint8 -> additional_input_len: size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 additional_input /\ disjoint_st st additional_input h0 /\ B.length additional_input = v additional_input_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v additional_input_len <= S.max_additional_input_length /\ footprint st h0 == footprint st h1 /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ repr st h1 == S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input)))
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Lib.IntTypes.size_t", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverCrypt.DRBG.invariant", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "EverCrypt.DRBG.disjoint_st", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.range", "Lib.IntTypes.U32", "LowStar.Monotonic.Buffer.length", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Prims.op_Negation", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_LessThanOrEqual", "Spec.HMAC_DRBG.max_additional_input_length", "Prims.eq2", "LowStar.Monotonic.Buffer.loc", "EverCrypt.DRBG.footprint", "EverCrypt.DRBG.preserves_freeable", "Prims.l_Exists", "FStar.Seq.Base.seq", "Spec.HMAC_DRBG.min_length", "FStar.Seq.Base.length", "Spec.HMAC_DRBG.max_length", "Spec.HMAC_DRBG.state", "EverCrypt.DRBG.repr", "Spec.HMAC_DRBG.reseed", "LowStar.Monotonic.Buffer.as_seq", "Prims.unit", "Spec.HMAC_DRBG.hmac_input_bound" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h inline_for_extraction noextract let disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem) = B.loc_disjoint (footprint st h) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) /// TR: the following pattern is necessary because, if we generically /// add such a pattern directly on `loc_includes_union_l`, then /// verification will blowup whenever both sides of `loc_includes` are /// `loc_union`s. We would like to break all unions on the /// right-hand-side of `loc_includes` first, using /// `loc_includes_union_r`. Here the pattern is on `footprint_s`, /// because we already expose the fact that `footprint` is a /// `loc_union`. (In other words, the pattern should be on every /// smallest location that is not exposed to be a `loc_union`.) /// val loc_includes_union_l_footprint_s: #a:supported_alg -> l1:B.loc -> l2:B.loc -> st:state_s a -> Lemma (requires B.loc_includes l1 (footprint_s st) \/ B.loc_includes l2 (footprint_s st)) (ensures B.loc_includes (B.loc_union l1 l2) (footprint_s st)) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s st))] /// Needed to prove that the footprint is disjoint from any fresh location val invariant_loc_in_footprint: #a:supported_alg -> st:state a -> h:HS.mem -> Lemma (requires invariant st h) (ensures B.loc_in (footprint st h) h) [SMTPat (invariant st h)] val frame_invariant: #a:supported_alg -> l:B.loc -> st:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires invariant st h0 /\ B.loc_disjoint l (footprint st h0) /\ B.modifies l h0 h1) (ensures invariant st h1 /\ repr st h0 == repr st h1) inline_for_extraction noextract let preserves_freeable #a (st:state a) (h0 h1:HS.mem) = freeable st h0 ==> freeable st h1 inline_for_extraction val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1) val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1) (** @type: true *) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`. @return DRBG state. Needs to be freed via `EverCrypt_DRBG_uninstantiate`."] val create: a:supported_alg -> ST (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ invariant st h1 /\ freeable st h1) inline_for_extraction noextract let instantiate_st (a:supported_alg) = st:state a -> personalization_string:B.buffer uint8 -> personalization_string_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 personalization_string /\ disjoint_st st personalization_string h0 /\ B.length personalization_string = v personalization_string_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v personalization_string_len <= S.max_personalization_string_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input nonce. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ S.min_length a / 2 <= Seq.length nonce /\ Seq.length nonce <= S.max_length /\ repr st h1 == S.instantiate entropy_input nonce (B.as_seq h0 personalization_string))) inline_for_extraction noextract
false
true
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reseed_st : a: EverCrypt.DRBG.supported_alg -> Type0
[]
EverCrypt.DRBG.reseed_st
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: EverCrypt.DRBG.supported_alg -> Type0
{ "end_col": 76, "end_line": 258, "start_col": 4, "start_line": 235 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 instantiate_st (a:supported_alg) = st:state a -> personalization_string:B.buffer uint8 -> personalization_string_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 personalization_string /\ disjoint_st st personalization_string h0 /\ B.length personalization_string = v personalization_string_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v personalization_string_len <= S.max_personalization_string_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input nonce. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ S.min_length a / 2 <= Seq.length nonce /\ Seq.length nonce <= S.max_length /\ repr st h1 == S.instantiate entropy_input nonce (B.as_seq h0 personalization_string)))
let instantiate_st (a: supported_alg) =
false
null
false
st: state a -> personalization_string: B.buffer uint8 -> personalization_string_len: size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 personalization_string /\ disjoint_st st personalization_string h0 /\ B.length personalization_string = v personalization_string_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v personalization_string_len <= S.max_personalization_string_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input nonce. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ S.min_length a / 2 <= Seq.length nonce /\ Seq.length nonce <= S.max_length /\ repr st h1 == S.instantiate entropy_input nonce (B.as_seq h0 personalization_string) ))
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "EverCrypt.DRBG.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Lib.IntTypes.size_t", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverCrypt.DRBG.invariant", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "EverCrypt.DRBG.disjoint_st", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.range", "Lib.IntTypes.U32", "LowStar.Monotonic.Buffer.length", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Prims.op_Negation", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_LessThanOrEqual", "Spec.HMAC_DRBG.max_personalization_string_length", "EverCrypt.DRBG.preserves_freeable", "Prims.eq2", "LowStar.Monotonic.Buffer.loc", "EverCrypt.DRBG.footprint", "Prims.l_Exists", "FStar.Seq.Base.seq", "Spec.HMAC_DRBG.min_length", "FStar.Seq.Base.length", "Spec.HMAC_DRBG.max_length", "Prims.op_Division", "Spec.HMAC_DRBG.state", "EverCrypt.DRBG.repr", "Spec.HMAC_DRBG.instantiate", "LowStar.Monotonic.Buffer.as_seq", "Prims.unit", "Spec.HMAC_DRBG.hmac_input_bound" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h inline_for_extraction noextract let disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem) = B.loc_disjoint (footprint st h) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) /// TR: the following pattern is necessary because, if we generically /// add such a pattern directly on `loc_includes_union_l`, then /// verification will blowup whenever both sides of `loc_includes` are /// `loc_union`s. We would like to break all unions on the /// right-hand-side of `loc_includes` first, using /// `loc_includes_union_r`. Here the pattern is on `footprint_s`, /// because we already expose the fact that `footprint` is a /// `loc_union`. (In other words, the pattern should be on every /// smallest location that is not exposed to be a `loc_union`.) /// val loc_includes_union_l_footprint_s: #a:supported_alg -> l1:B.loc -> l2:B.loc -> st:state_s a -> Lemma (requires B.loc_includes l1 (footprint_s st) \/ B.loc_includes l2 (footprint_s st)) (ensures B.loc_includes (B.loc_union l1 l2) (footprint_s st)) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s st))] /// Needed to prove that the footprint is disjoint from any fresh location val invariant_loc_in_footprint: #a:supported_alg -> st:state a -> h:HS.mem -> Lemma (requires invariant st h) (ensures B.loc_in (footprint st h) h) [SMTPat (invariant st h)] val frame_invariant: #a:supported_alg -> l:B.loc -> st:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires invariant st h0 /\ B.loc_disjoint l (footprint st h0) /\ B.modifies l h0 h1) (ensures invariant st h1 /\ repr st h0 == repr st h1) inline_for_extraction noextract let preserves_freeable #a (st:state a) (h0 h1:HS.mem) = freeable st h0 ==> freeable st h1 inline_for_extraction val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1) val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1) (** @type: true *) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`. @return DRBG state. Needs to be freed via `EverCrypt_DRBG_uninstantiate`."] val create: a:supported_alg -> ST (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ invariant st h1 /\ freeable st h1) inline_for_extraction noextract
false
true
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val instantiate_st : a: EverCrypt.DRBG.supported_alg -> Type0
[]
EverCrypt.DRBG.instantiate_st
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: EverCrypt.DRBG.supported_alg -> Type0
{ "end_col": 80, "end_line": 230, "start_col": 4, "start_line": 205 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "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 generate_st (a:supported_alg) = output:B.buffer uint8 -> st:state a -> n:size_t -> additional_input:B.buffer uint8 -> additional_input_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 output /\ B.live h0 additional_input /\ disjoint_st st output h0 /\ disjoint_st st additional_input h0 /\ B.disjoint output additional_input /\ B.length additional_input = v additional_input_len /\ v n = B.length output) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v n <= S.max_output_length /\ v additional_input_len <= S.max_additional_input_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (B.loc_union (B.loc_buffer output) (footprint st h0)) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ (let st1 = S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input) in match S.generate st1 (v n) (B.as_seq h0 additional_input) with | None -> False // Always reseeds, so generation cannot fail | Some (out, st_) -> repr st h1 == st_ /\ B.as_seq h1 output == out)))
let generate_st (a: supported_alg) =
false
null
false
output: B.buffer uint8 -> st: state a -> n: size_t -> additional_input: B.buffer uint8 -> additional_input_len: size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 output /\ B.live h0 additional_input /\ disjoint_st st output h0 /\ disjoint_st st additional_input h0 /\ B.disjoint output additional_input /\ B.length additional_input = v additional_input_len /\ v n = B.length output) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v n <= S.max_output_length /\ v additional_input_len <= S.max_additional_input_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (B.loc_union (B.loc_buffer output) (footprint st h0)) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ (let st1 = S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input) in match S.generate st1 (v n) (B.as_seq h0 additional_input) with | None -> False | Some (out, st_) -> repr st h1 == st_ /\ B.as_seq h1 output == out)))
{ "checked_file": "EverCrypt.DRBG.fsti.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.DRBG.fsti" }
[ "total" ]
[ "EverCrypt.DRBG.supported_alg", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "EverCrypt.DRBG.state", "Lib.IntTypes.size_t", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverCrypt.DRBG.invariant", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "EverCrypt.DRBG.disjoint_st", "LowStar.Monotonic.Buffer.disjoint", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.range", "Lib.IntTypes.U32", "LowStar.Monotonic.Buffer.length", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Prims.op_Negation", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_LessThanOrEqual", "Spec.HMAC_DRBG.max_output_length", "Spec.HMAC_DRBG.max_additional_input_length", "EverCrypt.DRBG.preserves_freeable", "Prims.eq2", "LowStar.Monotonic.Buffer.loc", "EverCrypt.DRBG.footprint", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_Exists", "FStar.Seq.Base.seq", "Spec.HMAC_DRBG.min_length", "FStar.Seq.Base.length", "Spec.HMAC_DRBG.max_length", "Spec.HMAC_DRBG.generate", "LowStar.Monotonic.Buffer.as_seq", "Prims.l_False", "Spec.Agile.HMAC.lbytes", "Spec.HMAC_DRBG.state", "EverCrypt.DRBG.repr", "Prims.logical", "Spec.HMAC_DRBG.reseed", "Prims.unit", "Spec.HMAC_DRBG.hmac_input_bound" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG #set-options "--max_ifuel 0 --max_fuel 0" /// HMAC-DRBG /// /// See 10.1.2 and B.2 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// /// This module implements /// - HMAC_DRBG_Instantiate_function /// - HMAC_DRBG_Reseed_function /// - HMAC_DRBG_Generate_function /// - HMAC_DRBG_Uninstantiate_function /// /// Internally, it uses Lib.RandomBuffer.System as the Get_entropy_input function, /// for instantiation, reseeding, and prediction resistance. /// /// - Supports SHA-1, SHA2-256, SHA2-384 and SHA2-512 /// /// - Supports reseeding /// /// - Supports optional personalization_string for instantiation /// /// - Supports optional additional_input for reseeding and generation /// /// - Always provides prediction resistance (i.e. reseeds before generation) /// /// - The internal state is (Key,V,reseed_counter) /// /// - The security_strength is the HMAC-strength of the hash algorithm as per p.54 of /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf /// /// - The minimum entropy for instantiation is 3/2 * security_strength. /// - entropy_input must have at least security_strength bits. /// - nonce must have at least 1/2 security_strength bits. /// - entropy_input and nonce can have at most max_length = 2^16 bits. /// /// - At most max_number_of_bits_per_request = 2^16 bits can be generated per request. /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it unfold let supported_alg = S.supported_alg //[@ CMacro ] let reseed_interval: n:size_t{v n == S.reseed_interval} = assert_norm (S.reseed_interval < pow2 32); normalize_term (mk_int S.reseed_interval) //[@ CMacro ] let max_output_length: n:size_t{v n == S.max_output_length} = assert_norm (S.max_output_length < pow2 32); normalize_term (mk_int S.max_output_length) //[@ CMacro ] let max_length: n:size_t{v n == S.max_length} = assert_norm (S.max_length < pow2 32); normalize_term (mk_int S.max_length) //[@ CMacro ] let max_personalization_string_length: n:size_t{v n == S.max_personalization_string_length} = assert_norm (S.max_personalization_string_length < pow2 32); normalize_term (mk_int S.max_personalization_string_length) //[@ CMacro ] let max_additional_input_length: n:size_t{v n == S.max_additional_input_length} = assert_norm (S.max_additional_input_length < pow2 32); normalize_term (mk_int S.max_additional_input_length) let min_length (a:supported_alg) : n:size_t{v n == S.min_length a} = assert_norm (S.min_length a < pow2 32); match a with | SHA1 -> normalize_term (mk_int (S.min_length SHA1)) | SHA2_256 | SHA2_384 | SHA2_512 -> normalize_term (mk_int (S.min_length SHA2_256)) /// This has a @CAbstractStruct attribute in the implementation. /// See https://github.com/FStarLang/karamel/issues/153 /// /// It instructs KaRaMeL to include only a forward-declarartion /// in the header file, forcing code to always use `state_s` abstractly /// through a pointer. inline_for_extraction noextract val state_s: supported_alg -> Type0 inline_for_extraction noextract let state a = B.pointer (state_s a) inline_for_extraction noextract val freeable_s: #a:supported_alg -> st:state_s a -> Type0 inline_for_extraction noextract let freeable (#a:supported_alg) (st:state a) (h:HS.mem) = B.freeable st /\ freeable_s (B.deref h st) val footprint_s: #a:supported_alg -> state_s a -> GTot B.loc let footprint (#a:supported_alg) (st:state a) (h:HS.mem) = B.loc_union (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) inline_for_extraction noextract val invariant_s: #a:supported_alg -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:supported_alg) (st:state a) (h:HS.mem) = B.live h st /\ B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s (B.deref h st)) /\ invariant_s (B.deref h st) h inline_for_extraction noextract let disjoint_st (#t:Type) (#a:supported_alg) (st:state a) (b:B.buffer t) (h:HS.mem) = B.loc_disjoint (footprint st h) (B.loc_buffer b) val repr: #a:supported_alg -> st:state a -> h:HS.mem -> GTot (S.state a) /// TR: the following pattern is necessary because, if we generically /// add such a pattern directly on `loc_includes_union_l`, then /// verification will blowup whenever both sides of `loc_includes` are /// `loc_union`s. We would like to break all unions on the /// right-hand-side of `loc_includes` first, using /// `loc_includes_union_r`. Here the pattern is on `footprint_s`, /// because we already expose the fact that `footprint` is a /// `loc_union`. (In other words, the pattern should be on every /// smallest location that is not exposed to be a `loc_union`.) /// val loc_includes_union_l_footprint_s: #a:supported_alg -> l1:B.loc -> l2:B.loc -> st:state_s a -> Lemma (requires B.loc_includes l1 (footprint_s st) \/ B.loc_includes l2 (footprint_s st)) (ensures B.loc_includes (B.loc_union l1 l2) (footprint_s st)) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s st))] /// Needed to prove that the footprint is disjoint from any fresh location val invariant_loc_in_footprint: #a:supported_alg -> st:state a -> h:HS.mem -> Lemma (requires invariant st h) (ensures B.loc_in (footprint st h) h) [SMTPat (invariant st h)] val frame_invariant: #a:supported_alg -> l:B.loc -> st:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires invariant st h0 /\ B.loc_disjoint l (footprint st h0) /\ B.modifies l h0 h1) (ensures invariant st h1 /\ repr st h0 == repr st h1) inline_for_extraction noextract let preserves_freeable #a (st:state a) (h0 h1:HS.mem) = freeable st h0 ==> freeable st h1 inline_for_extraction val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1) val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1) (** @type: true *) [@@ Comment "Create a DRBG state. @param a Hash algorithm to use. The possible instantiations are ... * `Spec_Hash_Definitions_SHA2_256`, * `Spec_Hash_Definitions_SHA2_384`, * `Spec_Hash_Definitions_SHA2_512`, and * `Spec_Hash_Definitions_SHA1`. @return DRBG state. Needs to be freed via `EverCrypt_DRBG_uninstantiate`."] val create: a:supported_alg -> ST (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ invariant st h1 /\ freeable st h1) inline_for_extraction noextract let instantiate_st (a:supported_alg) = st:state a -> personalization_string:B.buffer uint8 -> personalization_string_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 personalization_string /\ disjoint_st st personalization_string h0 /\ B.length personalization_string = v personalization_string_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v personalization_string_len <= S.max_personalization_string_length /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ footprint st h0 == footprint st h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input nonce. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ S.min_length a / 2 <= Seq.length nonce /\ Seq.length nonce <= S.max_length /\ repr st h1 == S.instantiate entropy_input nonce (B.as_seq h0 personalization_string))) inline_for_extraction noextract let reseed_st (a:supported_alg) = st:state a -> additional_input:B.buffer uint8 -> additional_input_len:size_t -> Stack bool (requires fun h0 -> invariant st h0 /\ B.live h0 additional_input /\ disjoint_st st additional_input h0 /\ B.length additional_input = v additional_input_len) (ensures fun h0 b h1 -> S.hmac_input_bound a; if not b then B.modifies B.loc_none h0 h1 else v additional_input_len <= S.max_additional_input_length /\ footprint st h0 == footprint st h1 /\ invariant st h1 /\ preserves_freeable st h0 h1 /\ B.modifies (footprint st h0) h0 h1 /\ (exists entropy_input. S.min_length a <= Seq.length entropy_input /\ Seq.length entropy_input <= S.max_length /\ repr st h1 == S.reseed (repr st h0) entropy_input (B.as_seq h0 additional_input))) inline_for_extraction noextract
false
true
EverCrypt.DRBG.fsti
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val generate_st : a: EverCrypt.DRBG.supported_alg -> Type0
[]
EverCrypt.DRBG.generate_st
{ "file_name": "providers/evercrypt/EverCrypt.DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: EverCrypt.DRBG.supported_alg -> Type0
{ "end_col": 38, "end_line": 295, "start_col": 4, "start_line": 263 }
Prims.Tot
val sha256_msg1_spec (src1 src2:quad32) : quad32
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_msg1_spec = opaque_make sha256_msg1_spec_def
val sha256_msg1_spec (src1 src2:quad32) : quad32 let sha256_msg1_spec =
false
null
false
opaque_make sha256_msg1_spec_def
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "Vale.X64.CryptoInstructions_s.sha256_msg1_spec_def" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst [@"opaque_to_smt"] let sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def irreducible let sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def let sha256_msg1_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3)))
false
true
Vale.X64.CryptoInstructions_s.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 sha256_msg1_spec (src1 src2:quad32) : quad32
[]
Vale.X64.CryptoInstructions_s.sha256_msg1_spec
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 74, "end_line": 65, "start_col": 42, "start_line": 65 }
Prims.Tot
val sha256_rnds2_spec (src1 src2 wk:quad32) : quad32
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def
val sha256_rnds2_spec (src1 src2 wk:quad32) : quad32 let sha256_rnds2_spec =
false
null
false
opaque_make sha256_rnds2_spec_def
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_def" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in
false
true
Vale.X64.CryptoInstructions_s.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 sha256_rnds2_spec (src1 src2 wk:quad32) : quad32
[]
Vale.X64.CryptoInstructions_s.sha256_rnds2_spec
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> wk: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 76, "end_line": 51, "start_col": 43, "start_line": 51 }
FStar.Pervasives.Lemma
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_msg2_spec_reveal = opaque_revealer (`%sha256_msg2_spec) sha256_msg2_spec sha256_msg2_spec_def
let sha256_msg2_spec_reveal =
false
null
true
opaque_revealer (`%sha256_msg2_spec) sha256_msg2_spec sha256_msg2_spec_def
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "lemma" ]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "Vale.X64.CryptoInstructions_s.sha256_msg2_spec", "Vale.X64.CryptoInstructions_s.sha256_msg2_spec_def" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst [@"opaque_to_smt"] let sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def irreducible let sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def let sha256_msg1_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3))) (v (add_mod w3 (_sigma0 SHA2_256 w4))) [@"opaque_to_smt"] let sha256_msg1_spec = opaque_make sha256_msg1_spec_def irreducible let sha256_msg1_spec_reveal = opaque_revealer (`%sha256_msg1_spec) sha256_msg1_spec sha256_msg1_spec_def let sha256_msg2_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w14 = uint_to_t src2.hi2 in let w15 = uint_to_t src2.hi3 in let w16 = add_mod (uint_to_t src1.lo0) (_sigma1 SHA2_256 w14) in let w17 = add_mod (uint_to_t src1.lo1) (_sigma1 SHA2_256 w15) in let w18 = add_mod (uint_to_t src1.hi2) (_sigma1 SHA2_256 w16) in let w19 = add_mod (uint_to_t src1.hi3) (_sigma1 SHA2_256 w17) in Mkfour (v w16) (v w17) (v w18) (v w19)
false
false
Vale.X64.CryptoInstructions_s.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 sha256_msg2_spec_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.X64.CryptoInstructions_s.sha256_msg2_spec == Vale.X64.CryptoInstructions_s.sha256_msg2_spec_def)
[]
Vale.X64.CryptoInstructions_s.sha256_msg2_spec_reveal
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.X64.CryptoInstructions_s.sha256_msg2_spec == Vale.X64.CryptoInstructions_s.sha256_msg2_spec_def)
{ "end_col": 116, "end_line": 78, "start_col": 42, "start_line": 78 }
Prims.Tot
val sha256_msg2_spec (src1 src2:quad32) : quad32
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_msg2_spec = opaque_make sha256_msg2_spec_def
val sha256_msg2_spec (src1 src2:quad32) : quad32 let sha256_msg2_spec =
false
null
false
opaque_make sha256_msg2_spec_def
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "Vale.X64.CryptoInstructions_s.sha256_msg2_spec_def" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst [@"opaque_to_smt"] let sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def irreducible let sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def let sha256_msg1_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3))) (v (add_mod w3 (_sigma0 SHA2_256 w4))) [@"opaque_to_smt"] let sha256_msg1_spec = opaque_make sha256_msg1_spec_def irreducible let sha256_msg1_spec_reveal = opaque_revealer (`%sha256_msg1_spec) sha256_msg1_spec sha256_msg1_spec_def let sha256_msg2_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w14 = uint_to_t src2.hi2 in let w15 = uint_to_t src2.hi3 in let w16 = add_mod (uint_to_t src1.lo0) (_sigma1 SHA2_256 w14) in let w17 = add_mod (uint_to_t src1.lo1) (_sigma1 SHA2_256 w15) in let w18 = add_mod (uint_to_t src1.hi2) (_sigma1 SHA2_256 w16) in let w19 = add_mod (uint_to_t src1.hi3) (_sigma1 SHA2_256 w17) in
false
true
Vale.X64.CryptoInstructions_s.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 sha256_msg2_spec (src1 src2:quad32) : quad32
[]
Vale.X64.CryptoInstructions_s.sha256_msg2_spec
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 74, "end_line": 77, "start_col": 42, "start_line": 77 }
FStar.Pervasives.Lemma
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_msg1_spec_reveal = opaque_revealer (`%sha256_msg1_spec) sha256_msg1_spec sha256_msg1_spec_def
let sha256_msg1_spec_reveal =
false
null
true
opaque_revealer (`%sha256_msg1_spec) sha256_msg1_spec sha256_msg1_spec_def
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "lemma" ]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "Vale.X64.CryptoInstructions_s.sha256_msg1_spec", "Vale.X64.CryptoInstructions_s.sha256_msg1_spec_def" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst [@"opaque_to_smt"] let sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def irreducible let sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def let sha256_msg1_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3))) (v (add_mod w3 (_sigma0 SHA2_256 w4)))
false
false
Vale.X64.CryptoInstructions_s.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 sha256_msg1_spec_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.X64.CryptoInstructions_s.sha256_msg1_spec == Vale.X64.CryptoInstructions_s.sha256_msg1_spec_def)
[]
Vale.X64.CryptoInstructions_s.sha256_msg1_spec_reveal
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.X64.CryptoInstructions_s.sha256_msg1_spec == Vale.X64.CryptoInstructions_s.sha256_msg1_spec_def)
{ "end_col": 116, "end_line": 66, "start_col": 42, "start_line": 66 }
FStar.Pervasives.Lemma
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def
let sha256_rnds2_spec_reveal =
false
null
true
opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "lemma" ]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "Vale.X64.CryptoInstructions_s.sha256_rnds2_spec", "Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_def" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst
false
false
Vale.X64.CryptoInstructions_s.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 sha256_rnds2_spec_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.X64.CryptoInstructions_s.sha256_rnds2_spec == Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_def)
[]
Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_reveal
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.X64.CryptoInstructions_s.sha256_rnds2_spec == Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_def)
{ "end_col": 120, "end_line": 52, "start_col": 43, "start_line": 52 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h')
let sha256_rnds2_spec_update (a b c d e f g h wk: word SHA2_256) =
false
null
false
let open FStar.UInt32 in let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h')
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Spec.Hash.Definitions.word", "Spec.Hash.Definitions.SHA2_256", "FStar.Pervasives.Native.Mktuple8", "FStar.UInt32.t", "FStar.UInt32.add_mod", "Spec.SHA2._Ch", "Spec.SHA2._Sigma1", "Spec.SHA2._Maj", "Spec.SHA2._Sigma0", "FStar.Pervasives.Native.tuple8" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2
false
true
Vale.X64.CryptoInstructions_s.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 sha256_rnds2_spec_update : a: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> b: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> c: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> d: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> e: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> f: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> g: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> h: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> wk: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> ((((((FStar.UInt32.t * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * FStar.UInt32.t) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256
[]
Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_update
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> b: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> c: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> d: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> e: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> f: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> g: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> h: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> wk: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256 -> ((((((FStar.UInt32.t * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * FStar.UInt32.t) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256) * Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA2_256
{ "end_col": 34, "end_line": 33, "start_col": 2, "start_line": 15 }
Prims.Tot
val sha256_msg1_spec_def (src1 src2: quad32) : quad32
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_msg1_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3))) (v (add_mod w3 (_sigma0 SHA2_256 w4)))
val sha256_msg1_spec_def (src1 src2: quad32) : quad32 let sha256_msg1_spec_def (src1 src2: quad32) : quad32 =
false
null
false
let open FStar.UInt32 in let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3))) (v (add_mod w3 (_sigma0 SHA2_256 w4)))
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.UInt32.v", "FStar.UInt32.add_mod", "Spec.SHA2._sigma0", "Spec.Hash.Definitions.SHA2_256", "FStar.UInt32.t", "FStar.UInt32.uint_to_t", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst [@"opaque_to_smt"] let sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def irreducible let sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def
false
true
Vale.X64.CryptoInstructions_s.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 sha256_msg1_spec_def (src1 src2: quad32) : quad32
[]
Vale.X64.CryptoInstructions_s.sha256_msg1_spec_def
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 49, "end_line": 64, "start_col": 4, "start_line": 55 }
Prims.Tot
val sha256_msg2_spec_def (src1 src2: quad32) : quad32
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_msg2_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w14 = uint_to_t src2.hi2 in let w15 = uint_to_t src2.hi3 in let w16 = add_mod (uint_to_t src1.lo0) (_sigma1 SHA2_256 w14) in let w17 = add_mod (uint_to_t src1.lo1) (_sigma1 SHA2_256 w15) in let w18 = add_mod (uint_to_t src1.hi2) (_sigma1 SHA2_256 w16) in let w19 = add_mod (uint_to_t src1.hi3) (_sigma1 SHA2_256 w17) in Mkfour (v w16) (v w17) (v w18) (v w19)
val sha256_msg2_spec_def (src1 src2: quad32) : quad32 let sha256_msg2_spec_def (src1 src2: quad32) : quad32 =
false
null
false
let open FStar.UInt32 in let w14 = uint_to_t src2.hi2 in let w15 = uint_to_t src2.hi3 in let w16 = add_mod (uint_to_t src1.lo0) (_sigma1 SHA2_256 w14) in let w17 = add_mod (uint_to_t src1.lo1) (_sigma1 SHA2_256 w15) in let w18 = add_mod (uint_to_t src1.hi2) (_sigma1 SHA2_256 w16) in let w19 = add_mod (uint_to_t src1.hi3) (_sigma1 SHA2_256 w17) in Mkfour (v w16) (v w17) (v w18) (v w19)
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.UInt32.v", "FStar.UInt32.t", "FStar.UInt32.add_mod", "FStar.UInt32.uint_to_t", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Spec.SHA2._sigma1", "Spec.Hash.Definitions.SHA2_256", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__lo0" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h') let sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst [@"opaque_to_smt"] let sha256_rnds2_spec = opaque_make sha256_rnds2_spec_def irreducible let sha256_rnds2_spec_reveal = opaque_revealer (`%sha256_rnds2_spec) sha256_rnds2_spec sha256_rnds2_spec_def let sha256_msg1_spec_def (src1 src2:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let w4 = uint_to_t src2.lo0 in let w3 = uint_to_t src1.hi3 in let w2 = uint_to_t src1.hi2 in let w1 = uint_to_t src1.lo1 in let w0 = uint_to_t src1.lo0 in Mkfour (v (add_mod w0 (_sigma0 SHA2_256 w1))) (v (add_mod w1 (_sigma0 SHA2_256 w2))) (v (add_mod w2 (_sigma0 SHA2_256 w3))) (v (add_mod w3 (_sigma0 SHA2_256 w4))) [@"opaque_to_smt"] let sha256_msg1_spec = opaque_make sha256_msg1_spec_def irreducible let sha256_msg1_spec_reveal = opaque_revealer (`%sha256_msg1_spec) sha256_msg1_spec sha256_msg1_spec_def
false
true
Vale.X64.CryptoInstructions_s.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 sha256_msg2_spec_def (src1 src2: quad32) : quad32
[]
Vale.X64.CryptoInstructions_s.sha256_msg2_spec_def
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 42, "end_line": 76, "start_col": 4, "start_line": 69 }
Prims.Tot
val sha256_rnds2_spec_def (src1 src2 wk: quad32) : quad32
[ { "abbrev": false, "full_module": "Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "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 sha256_rnds2_spec_def (src1 src2 wk:quad32) : quad32 = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1,b1,c1,d1,e1,f1,g1,h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2,b2,c2,d2,e2,f2,g2,h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst
val sha256_rnds2_spec_def (src1 src2 wk: quad32) : quad32 let sha256_rnds2_spec_def (src1 src2 wk: quad32) : quad32 =
false
null
false
let open FStar.UInt32 in let a0 = uint_to_t src2.hi3 in let b0 = uint_to_t src2.hi2 in let c0 = uint_to_t src1.hi3 in let d0 = uint_to_t src1.hi2 in let e0 = uint_to_t src2.lo1 in let f0 = uint_to_t src2.lo0 in let g0 = uint_to_t src1.lo1 in let h0 = uint_to_t src1.lo0 in let wk0 = uint_to_t wk.lo0 in let wk1 = uint_to_t wk.lo1 in let a1, b1, c1, d1, e1, f1, g1, h1 = sha256_rnds2_spec_update a0 b0 c0 d0 e0 f0 g0 h0 wk0 in let a2, b2, c2, d2, e2, f2, g2, h2 = sha256_rnds2_spec_update a1 b1 c1 d1 e1 f1 g1 h1 wk1 in let dst = Mkfour (v f2) (v e2) (v b2) (v a2) in dst
{ "checked_file": "Vale.X64.CryptoInstructions_s.fst.checked", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Spec.SHA2.fst.checked", "Spec.SHA2.fst.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.IntTypes.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.X64.CryptoInstructions_s.fst" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "FStar.UInt32.t", "Spec.Hash.Definitions.word", "Spec.Hash.Definitions.SHA2_256", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.UInt32.v", "FStar.Pervasives.Native.tuple8", "Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_update", "FStar.UInt32.uint_to_t", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3" ]
[]
module Vale.X64.CryptoInstructions_s open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Def.Words_s open Vale.Def.Words.Four_s open Spec.Hash.Definitions open Spec.SHA2 friend Lib.IntTypes friend Spec.SHA2 let sha256_rnds2_spec_update (a b c d e f g h wk : word SHA2_256) = let open FStar.UInt32 in // Interop with UInt-based SHA spec let a' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))))) in let b' = a in let c' = b in let d' = c in let e' = add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))) in let f' = e in let g' = f in let h' = g in (a', b', c', d', e', f', g', h')
false
true
Vale.X64.CryptoInstructions_s.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 sha256_rnds2_spec_def (src1 src2 wk: quad32) : quad32
[]
Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_def
{ "file_name": "vale/specs/hardware/Vale.X64.CryptoInstructions_s.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> wk: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 7, "end_line": 50, "start_col": 4, "start_line": 36 }
Prims.Tot
val parse_option_kind (k: parser_kind) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; }
val parse_option_kind (k: parser_kind) : Tot parser_kind let parse_option_kind (k: parser_kind) : Tot parser_kind =
false
null
false
{ parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None }
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.Mkparser_kind'", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.parser_kind_metadata_some" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32
false
true
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_option_kind (k: parser_kind) : Tot parser_kind
[]
LowParse.Spec.Option.parse_option_kind
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
k: LowParse.Spec.Base.parser_kind -> LowParse.Spec.Base.parser_kind
{ "end_col": 29, "end_line": 12, "start_col": 2, "start_line": 9 }
Prims.Tot
val serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t)) = fun x -> match x with | None -> Seq.empty | Some y -> serialize s y
val serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t)) let serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t)) =
false
null
false
function | None -> Seq.empty | Some y -> serialize s y
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "FStar.Pervasives.Native.option", "FStar.Seq.Base.empty", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Bytes.bytes", "LowParse.Spec.Base.bare_serializer" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 let parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; } let parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) = fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input)) let parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) = parser_kind_prop_equiv k p; match parse p b1, parse p b2 with | Some _, Some _ -> assert (injective_precond p b1 b2) | _ -> () let parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (parse_option_bare_injective p x)); parser_kind_prop_equiv k p; parser_kind_prop_equiv (parse_option_kind k) (parse_option_bare p); parse_option_bare p
false
false
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t))
[]
LowParse.Spec.Option.serialize_option_bare
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Base.serializer p -> LowParse.Spec.Base.bare_serializer (FStar.Pervasives.Native.option t)
{ "end_col": 27, "end_line": 38, "start_col": 2, "start_line": 36 }
Prims.Tot
val parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) = fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input))
val parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) let parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) =
false
null
false
fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input))
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "LowParse.Spec.Base.consumed_length", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.bare_parser" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 let parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; }
false
false
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t))
[]
LowParse.Spec.Option.parse_option_bare
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> LowParse.Spec.Base.bare_parser (FStar.Pervasives.Native.option t)
{ "end_col": 50, "end_line": 19, "start_col": 2, "start_line": 16 }
Prims.Tot
val serialize_option (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (u: squash (k.parser_kind_low > 0)) : Tot (serializer (parse_option p))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 serialize_option (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (u: squash (k.parser_kind_low > 0)) : Tot (serializer (parse_option p)) = serialize_option_bare_correct s; serialize_option_bare s
val serialize_option (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (u: squash (k.parser_kind_low > 0)) : Tot (serializer (parse_option p)) let serialize_option (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (u: squash (k.parser_kind_low > 0)) : Tot (serializer (parse_option p)) =
false
null
false
serialize_option_bare_correct s; serialize_option_bare s
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.squash", "Prims.b2t", "Prims.op_GreaterThan", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "LowParse.Spec.Option.serialize_option_bare", "Prims.unit", "LowParse.Spec.Option.serialize_option_bare_correct", "LowParse.Spec.Option.parse_option_kind", "FStar.Pervasives.Native.option", "LowParse.Spec.Option.parse_option" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 let parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; } let parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) = fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input)) let parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) = parser_kind_prop_equiv k p; match parse p b1, parse p b2 with | Some _, Some _ -> assert (injective_precond p b1 b2) | _ -> () let parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (parse_option_bare_injective p x)); parser_kind_prop_equiv k p; parser_kind_prop_equiv (parse_option_kind k) (parse_option_bare p); parse_option_bare p let serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t)) = fun x -> match x with | None -> Seq.empty | Some y -> serialize s y let serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0)) (ensures (serializer_correct (parse_option p) (serialize_option_bare s))) = parser_kind_prop_equiv k p
false
false
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_option (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (u: squash (k.parser_kind_low > 0)) : Tot (serializer (parse_option p))
[]
LowParse.Spec.Option.serialize_option
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Base.serializer p -> u29: Prims.squash (Mkparser_kind'?.parser_kind_low k > 0) -> LowParse.Spec.Base.serializer (LowParse.Spec.Option.parse_option p)
{ "end_col": 25, "end_line": 47, "start_col": 2, "start_line": 46 }
FStar.Pervasives.Lemma
val parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) = parser_kind_prop_equiv k p; match parse p b1, parse p b2 with | Some _, Some _ -> assert (injective_precond p b1 b2) | _ -> ()
val parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) let parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) =
false
null
true
parser_kind_prop_equiv k p; match parse p b1, parse p b2 with | Some _, Some _ -> assert (injective_precond p b1 b2) | _ -> ()
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Bytes.bytes", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "Prims._assert", "LowParse.Spec.Base.injective_precond", "Prims.unit", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.Option.parse_option_bare", "Prims.squash", "LowParse.Spec.Base.injective_postcond", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 let parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; } let parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) = fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input)) let parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2))
false
false
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2))
[]
LowParse.Spec.Option.parse_option_bare_injective
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> b1: LowParse.Bytes.bytes -> b2: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (requires LowParse.Spec.Base.injective_precond (LowParse.Spec.Option.parse_option_bare p) b1 b2) (ensures LowParse.Spec.Base.injective_postcond (LowParse.Spec.Option.parse_option_bare p) b1 b2)
{ "end_col": 11, "end_line": 27, "start_col": 2, "start_line": 24 }
FStar.Pervasives.Lemma
val serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0)) (ensures (serializer_correct (parse_option p) (serialize_option_bare s)))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0)) (ensures (serializer_correct (parse_option p) (serialize_option_bare s))) = parser_kind_prop_equiv k p
val serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0)) (ensures (serializer_correct (parse_option p) (serialize_option_bare s))) let serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0)) (ensures (serializer_correct (parse_option p) (serialize_option_bare s))) =
false
null
true
parser_kind_prop_equiv k p
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.Spec.Base.parser_kind_prop_equiv", "Prims.unit", "Prims.b2t", "Prims.op_GreaterThan", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.squash", "LowParse.Spec.Base.serializer_correct", "LowParse.Spec.Option.parse_option_kind", "FStar.Pervasives.Native.option", "LowParse.Spec.Option.parse_option", "LowParse.Spec.Option.serialize_option_bare", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 let parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; } let parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) = fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input)) let parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) = parser_kind_prop_equiv k p; match parse p b1, parse p b2 with | Some _, Some _ -> assert (injective_precond p b1 b2) | _ -> () let parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (parse_option_bare_injective p x)); parser_kind_prop_equiv k p; parser_kind_prop_equiv (parse_option_kind k) (parse_option_bare p); parse_option_bare p let serialize_option_bare (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot (bare_serializer (option t)) = fun x -> match x with | None -> Seq.empty | Some y -> serialize s y let serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0))
false
false
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_option_bare_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma (requires (k.parser_kind_low > 0)) (ensures (serializer_correct (parse_option p) (serialize_option_bare s)))
[]
LowParse.Spec.Option.serialize_option_bare_correct
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Base.serializer p -> FStar.Pervasives.Lemma (requires Mkparser_kind'?.parser_kind_low k > 0) (ensures LowParse.Spec.Base.serializer_correct (LowParse.Spec.Option.parse_option p) (LowParse.Spec.Option.serialize_option_bare s))
{ "end_col": 28, "end_line": 43, "start_col": 2, "start_line": 43 }
Prims.Tot
val parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "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 parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t)) = Classical.forall_intro_2 (fun x -> Classical.move_requires (parse_option_bare_injective p x)); parser_kind_prop_equiv k p; parser_kind_prop_equiv (parse_option_kind k) (parse_option_bare p); parse_option_bare p
val parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t)) let parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t)) =
false
null
false
Classical.forall_intro_2 (fun x -> Classical.move_requires (parse_option_bare_injective p x)); parser_kind_prop_equiv k p; parser_kind_prop_equiv (parse_option_kind k) (parse_option_bare p); parse_option_bare p
{ "checked_file": "LowParse.Spec.Option.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.Option.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Option.parse_option_bare", "Prims.unit", "LowParse.Spec.Base.parser_kind_prop_equiv", "FStar.Pervasives.Native.option", "LowParse.Spec.Option.parse_option_kind", "FStar.Classical.forall_intro_2", "LowParse.Bytes.bytes", "Prims.l_imp", "LowParse.Spec.Base.injective_precond", "LowParse.Spec.Base.injective_postcond", "FStar.Classical.move_requires", "LowParse.Spec.Option.parse_option_bare_injective", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.Option include LowParse.Spec.Base module Seq = FStar.Seq module U8 = FStar.UInt8 module U32 = FStar.UInt32 let parse_option_kind (k: parser_kind) : Tot parser_kind = { parser_kind_metadata = None; parser_kind_low = 0; parser_kind_high = k.parser_kind_high; parser_kind_subkind = None; } let parse_option_bare (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (bare_parser (option t)) = fun (input: bytes) -> match parse p input with | Some (data, consumed) -> Some (Some data, consumed) | _ -> Some (None, (0 <: consumed_length input)) let parse_option_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) (b1 b2: bytes) : Lemma (requires (injective_precond (parse_option_bare p) b1 b2)) (ensures (injective_postcond (parse_option_bare p) b1 b2)) = parser_kind_prop_equiv k p; match parse p b1, parse p b2 with | Some _, Some _ -> assert (injective_precond p b1 b2) | _ -> ()
false
false
LowParse.Spec.Option.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_option (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser (parse_option_kind k) (option t))
[]
LowParse.Spec.Option.parse_option
{ "file_name": "src/lowparse/LowParse.Spec.Option.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> LowParse.Spec.Base.parser (LowParse.Spec.Option.parse_option_kind k) (FStar.Pervasives.Native.option t)
{ "end_col": 21, "end_line": 33, "start_col": 2, "start_line": 30 }
Prims.Tot
val u2:universe
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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 u2 : universe = R.pack_universe (R.Uv_Succ u1)
val u2:universe let u2:universe =
false
null
false
R.pack_universe (R.Uv_Succ u1)
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "FStar.Reflection.V2.Builtins.pack_universe", "FStar.Reflection.V2.Data.Uv_Succ", "Pulse.Syntax.Pure.u1" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x let u0 : universe = R.pack_universe R.Uv_Zero
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val u2:universe
[]
Pulse.Syntax.Pure.u2
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.universe
{ "end_col": 50, "end_line": 19, "start_col": 20, "start_line": 19 }
Prims.Tot
val u0:universe
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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 u0 : universe = R.pack_universe R.Uv_Zero
val u0:universe let u0:universe =
false
null
false
R.pack_universe R.Uv_Zero
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "FStar.Reflection.V2.Builtins.pack_universe", "FStar.Reflection.V2.Data.Uv_Zero" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val u0:universe
[]
Pulse.Syntax.Pure.u0
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.universe
{ "end_col": 45, "end_line": 17, "start_col": 20, "start_line": 17 }
Prims.Tot
val u1:universe
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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 u1 : universe = R.pack_universe (R.Uv_Succ u0)
val u1:universe let u1:universe =
false
null
false
R.pack_universe (R.Uv_Succ u0)
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "FStar.Reflection.V2.Builtins.pack_universe", "FStar.Reflection.V2.Data.Uv_Succ", "Pulse.Syntax.Pure.u0" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val u1:universe
[]
Pulse.Syntax.Pure.u1
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.universe
{ "end_col": 50, "end_line": 18, "start_col": 20, "start_line": 18 }
Prims.Tot
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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 u_zero = u0
let u_zero =
false
null
false
u0
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "Pulse.Syntax.Pure.u0" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x let u0 : universe = R.pack_universe R.Uv_Zero let u1 : universe = R.pack_universe (R.Uv_Succ u0) let u2 : universe = R.pack_universe (R.Uv_Succ u1)
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val u_zero : Pulse.Syntax.Base.universe
[]
Pulse.Syntax.Pure.u_zero
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.universe
{ "end_col": 15, "end_line": 21, "start_col": 13, "start_line": 21 }
Prims.Tot
val u_var (s: string) : universe
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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 u_var (s:string) : universe = R.pack_universe (R.Uv_Name (R.pack_ident (s, FStar.Range.range_0)))
val u_var (s: string) : universe let u_var (s: string) : universe =
false
null
false
R.pack_universe (R.Uv_Name (R.pack_ident (s, FStar.Range.range_0)))
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "Prims.string", "FStar.Reflection.V2.Builtins.pack_universe", "FStar.Reflection.V2.Data.Uv_Name", "FStar.Reflection.V2.Builtins.pack_ident", "FStar.Pervasives.Native.Mktuple2", "FStar.Range.range", "FStar.Range.range_0", "Pulse.Syntax.Base.universe" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x let u0 : universe = R.pack_universe R.Uv_Zero let u1 : universe = R.pack_universe (R.Uv_Succ u0) let u2 : universe = R.pack_universe (R.Uv_Succ u1) let u_zero = u0 let u_succ (u:universe) : universe = R.pack_universe (R.Uv_Succ u)
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val u_var (s: string) : universe
[]
Pulse.Syntax.Pure.u_var
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
s: Prims.string -> Pulse.Syntax.Base.universe
{ "end_col": 69, "end_line": 25, "start_col": 2, "start_line": 25 }
Prims.Tot
val mk_bvar (s: string) (r: Range.range) (i: index) : term
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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_bvar (s:string) (r:Range.range) (i:index) : term = tm_bvar {bv_index=i;bv_ppname=mk_ppname (RT.seal_pp_name s) r}
val mk_bvar (s: string) (r: Range.range) (i: index) : term let mk_bvar (s: string) (r: Range.range) (i: index) : term =
false
null
false
tm_bvar ({ bv_index = i; bv_ppname = mk_ppname (RT.seal_pp_name s) r })
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "Prims.string", "FStar.Range.range", "Pulse.Syntax.Base.index", "Pulse.Syntax.Pure.tm_bvar", "Pulse.Syntax.Base.Mkbv", "Pulse.Syntax.Base.mk_ppname", "FStar.Reflection.Typing.seal_pp_name", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x let u0 : universe = R.pack_universe R.Uv_Zero let u1 : universe = R.pack_universe (R.Uv_Succ u0) let u2 : universe = R.pack_universe (R.Uv_Succ u1) let u_zero = u0 let u_succ (u:universe) : universe = R.pack_universe (R.Uv_Succ u) let u_var (s:string) : universe = R.pack_universe (R.Uv_Name (R.pack_ident (s, FStar.Range.range_0))) let u_max (u0 u1:universe) : universe = R.pack_universe (R.Uv_Max [u0; u1]) let u_unknown : universe = R.pack_universe R.Uv_Unk let tm_bvar (bv:bv) : term = tm_fstar (R.pack_ln (R.Tv_BVar (R.pack_bv (RT.make_bv_with_name bv.bv_ppname.name bv.bv_index)))) bv.bv_ppname.range let tm_var (nm:nm) : term = tm_fstar (R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv_with_name nm.nm_ppname.name nm.nm_index)))) nm.nm_ppname.range let tm_fvar (l:fv) : term = tm_fstar (R.pack_ln (R.Tv_FVar (R.pack_fv l.fv_name))) l.fv_range let tm_uinst (l:fv) (us:list universe) : term = tm_fstar (R.pack_ln (R.Tv_UInst (R.pack_fv l.fv_name) us)) l.fv_range let tm_constant (c:constant) : term = tm_fstar (R.pack_ln (R.Tv_Const c)) FStar.Range.range_0 let tm_refine (b:binder) (t:term) : term = let rb : R.simple_binder = RT.mk_simple_binder b.binder_ppname.name (elab_term b.binder_ty) in tm_fstar (R.pack_ln (R.Tv_Refine rb (elab_term t))) FStar.Range.range_0 let tm_let (t e1 e2:term) : term = let rb : R.simple_binder = RT.mk_simple_binder RT.pp_name_default (elab_term t) in tm_fstar (R.pack_ln (R.Tv_Let false [] rb (elab_term e1) (elab_term e2))) FStar.Range.range_0 let tm_pureapp (head:term) (q:option qualifier) (arg:term) : term = tm_fstar (R.mk_app (elab_term head) [(elab_term arg, elab_qual q)]) FStar.Range.range_0 let tm_arrow (b:binder) (q:option qualifier) (c:comp) : term = tm_fstar (mk_arrow_with_name b.binder_ppname.name (elab_term b.binder_ty, elab_qual q) (elab_comp c)) FStar.Range.range_0 let tm_type (u:universe) : term = tm_fstar (R.pack_ln (R.Tv_Type u)) FStar.Range.range_0
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_bvar (s: string) (r: Range.range) (i: index) : term
[]
Pulse.Syntax.Pure.mk_bvar
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
s: Prims.string -> r: FStar.Range.range -> i: Pulse.Syntax.Base.index -> Pulse.Syntax.Base.term
{ "end_col": 64, "end_line": 76, "start_col": 2, "start_line": 76 }
Prims.Tot
val null_bvar (i: index) : term
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Readback", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "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 null_bvar (i:index) : term = tm_bvar {bv_index=i;bv_ppname=ppname_default}
val null_bvar (i: index) : term let null_bvar (i: index) : term =
false
null
false
tm_bvar ({ bv_index = i; bv_ppname = ppname_default })
{ "checked_file": "Pulse.Syntax.Pure.fst.checked", "dependencies": [ "Pulse.Syntax.Base.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Readback.fsti.checked", "Pulse.Elaborate.Pure.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Pure.fst" }
[ "total" ]
[ "Pulse.Syntax.Base.index", "Pulse.Syntax.Pure.tm_bvar", "Pulse.Syntax.Base.Mkbv", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Pure module R = FStar.Reflection.V2 module T = FStar.Tactics.V2 module RT = FStar.Reflection.Typing open Pulse.Syntax.Base open Pulse.Elaborate.Pure open Pulse.Readback open Pulse.Reflection.Util let (let?) (f:option 'a) (g:'a -> option 'b) : option 'b = match f with | None -> None | Some x -> g x let u0 : universe = R.pack_universe R.Uv_Zero let u1 : universe = R.pack_universe (R.Uv_Succ u0) let u2 : universe = R.pack_universe (R.Uv_Succ u1) let u_zero = u0 let u_succ (u:universe) : universe = R.pack_universe (R.Uv_Succ u) let u_var (s:string) : universe = R.pack_universe (R.Uv_Name (R.pack_ident (s, FStar.Range.range_0))) let u_max (u0 u1:universe) : universe = R.pack_universe (R.Uv_Max [u0; u1]) let u_unknown : universe = R.pack_universe R.Uv_Unk let tm_bvar (bv:bv) : term = tm_fstar (R.pack_ln (R.Tv_BVar (R.pack_bv (RT.make_bv_with_name bv.bv_ppname.name bv.bv_index)))) bv.bv_ppname.range let tm_var (nm:nm) : term = tm_fstar (R.pack_ln (R.Tv_Var (R.pack_namedv (RT.make_namedv_with_name nm.nm_ppname.name nm.nm_index)))) nm.nm_ppname.range let tm_fvar (l:fv) : term = tm_fstar (R.pack_ln (R.Tv_FVar (R.pack_fv l.fv_name))) l.fv_range let tm_uinst (l:fv) (us:list universe) : term = tm_fstar (R.pack_ln (R.Tv_UInst (R.pack_fv l.fv_name) us)) l.fv_range let tm_constant (c:constant) : term = tm_fstar (R.pack_ln (R.Tv_Const c)) FStar.Range.range_0 let tm_refine (b:binder) (t:term) : term = let rb : R.simple_binder = RT.mk_simple_binder b.binder_ppname.name (elab_term b.binder_ty) in tm_fstar (R.pack_ln (R.Tv_Refine rb (elab_term t))) FStar.Range.range_0 let tm_let (t e1 e2:term) : term = let rb : R.simple_binder = RT.mk_simple_binder RT.pp_name_default (elab_term t) in tm_fstar (R.pack_ln (R.Tv_Let false [] rb (elab_term e1) (elab_term e2))) FStar.Range.range_0 let tm_pureapp (head:term) (q:option qualifier) (arg:term) : term = tm_fstar (R.mk_app (elab_term head) [(elab_term arg, elab_qual q)]) FStar.Range.range_0 let tm_arrow (b:binder) (q:option qualifier) (c:comp) : term = tm_fstar (mk_arrow_with_name b.binder_ppname.name (elab_term b.binder_ty, elab_qual q) (elab_comp c)) FStar.Range.range_0 let tm_type (u:universe) : term = tm_fstar (R.pack_ln (R.Tv_Type u)) FStar.Range.range_0 let mk_bvar (s:string) (r:Range.range) (i:index) : term = tm_bvar {bv_index=i;bv_ppname=mk_ppname (RT.seal_pp_name s) r} let null_var (v:var) : term = tm_var {nm_index=v;nm_ppname=ppname_default}
false
true
Pulse.Syntax.Pure.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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val null_bvar (i: index) : term
[]
Pulse.Syntax.Pure.null_bvar
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Pure.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
i: Pulse.Syntax.Base.index -> Pulse.Syntax.Base.term
{ "end_col": 47, "end_line": 82, "start_col": 2, "start_line": 82 }